ErrorWithCause: add .code and .domain

This commit is contained in:
Marc Rousavy 2021-02-23 15:59:07 +01:00
parent d60a3a34bc
commit 934106e837
3 changed files with 22 additions and 1 deletions

View File

@ -46,6 +46,8 @@ The `CameraError` type is a baseclass type for all other errors and provides the
* `message`: A non-localized message text that provides a more information and context about the error and possibly problematic values. * `message`: A non-localized message text that provides a more information and context about the error and possibly problematic values.
* (optional) `cause`: An `ErrorWithCause` instance that provides information about the cause of the error. * (optional) `cause`: An `ErrorWithCause` instance that provides information about the cause of the error.
* `cause.message`: The message of the error that caused the camera error. This is localized on iOS. * `cause.message`: The message of the error that caused the camera error. This is localized on iOS.
* (iOS) `cause.code`: The native error's error-code. (iOS only)
* (iOS) `cause.domain`: The native error's domain. (iOS only)
* (iOS) `cause.details`: More dictionary-style information about the cause. (iOS only) * (iOS) `cause.details`: More dictionary-style information about the cause. (iOS only)
* (Android) `cause.stacktrace`: A native Java stacktrace for the cause. * (Android) `cause.stacktrace`: A native Java stacktrace for the cause.
* (optional) `cause.cause`: The cause that caused the given error. (Recursive) * (optional) `cause.cause`: The cause that caused the given error. (Recursive)

View File

@ -463,7 +463,12 @@ final class CameraView: UIView {
var causeDictionary: [String: Any]? var causeDictionary: [String: Any]?
if let cause = cause { if let cause = cause {
causeDictionary = ["message": cause.localizedDescription, "details": cause.userInfo] causeDictionary = [
"code": cause.code,
"domain": cause.domain,
"message": cause.localizedDescription,
"details": cause.userInfo
]
} }
onError([ onError([
"code": error.code, "code": error.code,

View File

@ -37,6 +37,20 @@ export type SystemError = 'system/no-camera-manager';
export type UnknownError = 'unknown/unknown'; export type UnknownError = 'unknown/unknown';
export interface ErrorWithCause { export interface ErrorWithCause {
/**
* The native error's code.
*
* * iOS: `NSError.code`
* * Android: N/A
*/
code?: number;
/**
* The native error's domain.
*
* * iOS: `NSError.domain`
* * Android: N/A
*/
domain?: string;
/** /**
* The native error description (Localized on iOS) * The native error description (Localized on iOS)
* *