@appsemble/lang-sdk
Version:
Language SDK for Appsemble
30 lines • 1.16 kB
JavaScript
/**
* This error may be thrown by actions.
*/
export class ActionError extends Error {
constructor(options) {
const { cause, data, definition } = options;
super(`An error occurred while running ${definition.type}`, { cause });
this.data = data;
this.definition = definition;
if (typeof cause === 'object' && cause != null && 'response' in cause) {
const { response } = cause;
if (typeof response === 'object' && response != null && 'status' in response) {
const responseStatus = response.status;
if (responseStatus && typeof responseStatus === 'number') {
this.status = responseStatus;
}
}
}
// eslint-disable-next-line unicorn/custom-error-definition
this.name = `ActionError(${definition.type})`;
this.cause = cause;
if (cause instanceof Error && cause.stack) {
this.stack += `\n\n${cause.stack
.split('\n')
.map((line) => ` ${line}`)
.join('\n')}`;
}
}
}
//# sourceMappingURL=ActionError.js.map