diff --git a/lib/modules/functions/index.js b/lib/modules/functions/index.js index 47ed054b..bf4ac63a 100644 --- a/lib/modules/functions/index.js +++ b/lib/modules/functions/index.js @@ -18,6 +18,26 @@ import type { export const NAMESPACE = 'functions'; export const MODULE_NAME = 'RNFirebaseFunctions'; +/** + * ------------- + * INTERNALS + * ------------- + */ +function errorOrResult(possibleError): HttpsCallablePromise { + if (isObject(possibleError) && possibleError.__error) { + const { code, message, details } = possibleError; + return Promise.reject( + new HttpsError( + statics.HttpsErrorCode[code] || statics.HttpsErrorCode.UNKNOWN, + message, + details + ) + ); + } + + return Promise.resolve(possibleError); +} + export default class Functions extends ModuleBase { constructor(app: App) { super(app, { @@ -41,29 +61,9 @@ export default class Functions extends ModuleBase { httpsCallable(name: string): HttpsCallable { return (data?: any): HttpsCallablePromise => { const promise = getNativeModule(this).httpsCallable(name, { data }); - return promise.then(this._errorOrResult); + return promise.then(errorOrResult); }; } - - /** - * ------------- - * INTERNALS - * ------------- - */ - _errorOrResult(possibleError): HttpsCallablePromise { - if (isObject(possibleError) && possibleError.__error) { - const { code, message, details } = possibleError; - return Promise.reject( - new HttpsError( - statics.HttpsErrorCode[code] || statics.HttpsErrorCode.UNKNOWN, - message, - details - ) - ); - } - - return Promise.resolve(possibleError); - } } export const statics: { HttpsErrorCode: HttpsErrorCode } = {