@darlean/base
Version:
Base types and definitions for creating Darlean actors and suites
31 lines (30 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toApplicationError = exports.APPLICATION_ERROR_UNEXPECTED_ERROR = exports.APPLICATION_ERROR_FRAMEWORK_ERROR = void 0;
const shared_1 = require("./shared");
exports.APPLICATION_ERROR_FRAMEWORK_ERROR = 'FRAMEWORK_ERROR';
exports.APPLICATION_ERROR_UNEXPECTED_ERROR = 'UNEXPECTED_ERROR';
function toApplicationError(e) {
if (e instanceof shared_1.ApplicationError) {
return e;
}
if (e instanceof shared_1.FrameworkError) {
return new shared_1.ApplicationError(exports.APPLICATION_ERROR_FRAMEWORK_ERROR, e.code, undefined, e.stack, [e], e.message);
}
if (typeof e === 'object') {
const err = e;
return new shared_1.ApplicationError(err.name, undefined, undefined, err.stack, undefined, err.message);
}
else if (typeof e === 'string') {
if (e.includes(' ')) {
return new shared_1.ApplicationError(exports.APPLICATION_ERROR_UNEXPECTED_ERROR, e);
}
else {
return new shared_1.ApplicationError(e, e);
}
}
else {
return new shared_1.ApplicationError(exports.APPLICATION_ERROR_UNEXPECTED_ERROR, 'Unexpected error');
}
}
exports.toApplicationError = toApplicationError;