js: cleanup error util

This commit is contained in:
Salakar 2017-03-07 17:35:48 +00:00
parent a3f3cf930a
commit 51c63b2f3e
2 changed files with 16 additions and 3 deletions

View File

@ -132,11 +132,17 @@ export default class Reference extends ReferenceBase {
})
.catch((error) => {
const firebaseError = this.db._toFirebaseError(error);
if (isFunction(failureCallback)) failureCallback(firebaseError);
if (isFunction(failureCallback)) return failureCallback(firebaseError);
return Promise.reject(firebaseError);
});
}
/**
*
* @param eventType
* @param origCB
* @returns {*}
*/
off(eventType?: string = '', origCB?: () => any) {
const path = this._dbPath();
const modifiersString = this.query.getModifiersString();

View File

@ -9,8 +9,15 @@ const _handler = (resolve, reject, errorPrefix, err, resp) => {
setImmediate(() => {
if (err) {
const firebaseError = new Error(err.message);
firebaseError.code = toWebSDKErrorCode(err.code || err.errCode || err.errorCode || '', errorPrefix);
return reject(errorPrefix ? firebaseError : err);
if (isObject(err)) {
Object.keys(err).forEach(key => Object.defineProperty(firebaseError, key, { value: err[key] }));
if (errorPrefix) {
firebaseError.code = toWebSDKErrorCode(err.code || '', errorPrefix);
}
}
return reject(firebaseError);
}
return resolve(resp);
});