[js][functions] misc HttpsError
This commit is contained in:
parent
73d915f192
commit
d26f7a17ad
11
lib/modules/functions/HttpsError.js
Normal file
11
lib/modules/functions/HttpsError.js
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -6,27 +6,18 @@ import ModuleBase from '../../utils/ModuleBase';
|
|||||||
import { isObject } from '../../utils';
|
import { isObject } from '../../utils';
|
||||||
import { getNativeModule } from '../../utils/native';
|
import { getNativeModule } from '../../utils/native';
|
||||||
|
|
||||||
|
import type App from '../core/app';
|
||||||
|
import HttpsError from './HttpsError';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
HttpsCallable,
|
HttpsCallable,
|
||||||
HttpsErrorCode,
|
HttpsErrorCode,
|
||||||
FunctionsErrorCode,
|
|
||||||
HttpsCallablePromise,
|
HttpsCallablePromise,
|
||||||
} from './types.flow';
|
} from './types.flow';
|
||||||
import type App from '../core/app';
|
|
||||||
|
|
||||||
export const NAMESPACE = 'functions';
|
export const NAMESPACE = 'functions';
|
||||||
export const MODULE_NAME = 'RNFirebaseFunctions';
|
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 {
|
export default class Functions extends ModuleBase {
|
||||||
constructor(app: App) {
|
constructor(app: App) {
|
||||||
super(app, {
|
super(app, {
|
||||||
@ -62,7 +53,13 @@ export default class Functions extends ModuleBase {
|
|||||||
_errorOrResult(possibleError): HttpsCallablePromise {
|
_errorOrResult(possibleError): HttpsCallablePromise {
|
||||||
if (isObject(possibleError) && possibleError.__error) {
|
if (isObject(possibleError) && possibleError.__error) {
|
||||||
const { code, message, details } = possibleError;
|
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);
|
return Promise.resolve(possibleError);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user