From d26f7a17adf67a040168a99766e21cee4fc54fd2 Mon Sep 17 00:00:00 2001 From: Salakar Date: Sun, 6 May 2018 13:50:39 +0100 Subject: [PATCH] [js][functions] misc HttpsError --- lib/modules/functions/HttpsError.js | 11 +++++++++++ lib/modules/functions/index.js | 23 ++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 lib/modules/functions/HttpsError.js diff --git a/lib/modules/functions/HttpsError.js b/lib/modules/functions/HttpsError.js new file mode 100644 index 00000000..6bded74a --- /dev/null +++ b/lib/modules/functions/HttpsError.js @@ -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; + } +} diff --git a/lib/modules/functions/index.js b/lib/modules/functions/index.js index f690d655..47ed054b 100644 --- a/lib/modules/functions/index.js +++ b/lib/modules/functions/index.js @@ -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);