[js][functions] move errorOrResult fn outside class

This commit is contained in:
Salakar 2018-05-07 19:32:20 +01:00
parent 051ae10ad1
commit 6040136a15
1 changed files with 21 additions and 21 deletions

View File

@ -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 } = {