[js][functions] misc HttpsError

This commit is contained in:
Salakar 2018-05-06 13:50:39 +01:00
parent 73d915f192
commit d26f7a17ad
2 changed files with 21 additions and 13 deletions

View File

@ -0,0 +1,11 @@
import type { FunctionsErrorCode } from './types.flow';
export default class HttpsError extends Error {
+details: ?any;
+code: FunctionsErrorCode;
constructor(code: FunctionsErrorCode, message?: string, details?: any) {
super(message);
this.details = details;
this.code = code;
}
}

View File

@ -6,27 +6,18 @@ import ModuleBase from '../../utils/ModuleBase';
import { isObject } from '../../utils';
import { getNativeModule } from '../../utils/native';
import type App from '../core/app';
import HttpsError from './HttpsError';
import type {
HttpsCallable,
HttpsErrorCode,
FunctionsErrorCode,
HttpsCallablePromise,
} from './types.flow';
import type App from '../core/app';
export const NAMESPACE = 'functions';
export const MODULE_NAME = 'RNFirebaseFunctions';
class HttpsError extends Error {
+details: ?any;
+code: FunctionsErrorCode;
constructor(code: string, message?: string, details?: any) {
super(message);
this.details = details;
this.code = statics.HttpsErrorCode[code] || statics.HttpsErrorCode.UNKNOWN;
}
}
export default class Functions extends ModuleBase {
constructor(app: App) {
super(app, {
@ -62,7 +53,13 @@ export default class Functions extends ModuleBase {
_errorOrResult(possibleError): HttpsCallablePromise {
if (isObject(possibleError) && possibleError.__error) {
const { code, message, details } = possibleError;
return Promise.reject(new HttpsError(code, message, details));
return Promise.reject(
new HttpsError(
statics.HttpsErrorCode[code] || statics.HttpsErrorCode.UNKNOWN,
message,
details
)
);
}
return Promise.resolve(possibleError);