diff --git a/src/common/NativeError.js b/src/common/NativeError.js new file mode 100644 index 00000000..f973543c --- /dev/null +++ b/src/common/NativeError.js @@ -0,0 +1,14 @@ +import type { + NativeErrorObject, + NativeErrorInterface, +} from './commonTypes.flow'; + +export default class NativeError extends Error implements NativeErrorInterface { + constructor(nativeError: NativeErrorObject) { + super(nativeError.message); + this.code = nativeError.code; + this.message = nativeError.message; + this.nativeErrorCode = nativeError.nativeErrorCode; + this.nativeErrorMessage = nativeError.nativeErrorMessage; + } +} diff --git a/src/common/commonTypes.flow.js b/src/common/commonTypes.flow.js new file mode 100644 index 00000000..228a72db --- /dev/null +++ b/src/common/commonTypes.flow.js @@ -0,0 +1,19 @@ +export type NativeErrorObject = { + code: string, + message: string, + nativeErrorCode: string | number, + nativeErrorMessage: string, +}; + +export type NativeErrorResponse = { + error: NativeErrorObject, + // everything else + [key: string]: ?any, +}; + +export interface NativeErrorInterface extends Error { + +code: string; + +message: string; + +nativeErrorCode: string | number; + +nativeErrorMessage: string; +}