@openinc/parse-server-opendash
Version:
Parse Server Cloud Code for open.INC Stack.
25 lines (24 loc) • 769 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.catchError = catchError;
/**
* Catch errors from a promise and return them as an array or the result
* @param promise A promise to catch errors from
* @param errorsToCatch An array of error classes to catch. If not provided, all errors will be caught.
* @returns The promise result or an array with the error
*/
async function catchError(promise, errorsToCatch) {
try {
const data = await promise;
return [undefined, data];
}
catch (error) {
if (errorsToCatch === undefined) {
return [error];
}
if (errorsToCatch.some((e) => error instanceof e)) {
return [error];
}
throw error;
}
}
;