[common] NativeError class implementation

This commit is contained in:
Salakar
2018-09-21 00:04:14 +01:00
parent 6dcba98e14
commit 8a9bd700bb
2 changed files with 33 additions and 0 deletions

14
src/common/NativeError.js Normal file
View File

@@ -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;
}
}

View File

@@ -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;
}