@darlean/base
Version:
Base types and definitions for creating Darlean actors and suites
59 lines (58 loc) • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrameworkError = exports.ApplicationError = void 0;
const utils_1 = require("@darlean/utils");
/**
* Implementation of an {@link IActionError} that occurred in application code while
* performing an action on an actor.
*/
class ApplicationError extends Error {
constructor(code, template, parameters, stack, nested, message) {
super(code);
this.kind = 'application';
this.code = code;
this.parameters = parameters; // ? formatAllAttributes(parameters) : undefined;
this.template = template;
if (template === undefined) {
this.message = message ?? code;
}
else {
this.message = parameters ? (0, utils_1.replaceArguments)(template, parameters) : template;
}
if (haveStack(stack)) {
this.stack = stack;
}
this.nested = nested;
}
}
exports.ApplicationError = ApplicationError;
// Stack traces always contain the error message + additional stack lines.
// When only error msg is present, we do not consider it a real stack trace. We want
// to have node derive a new stack trace instead.
function haveStack(stack) {
return stack?.includes('\n');
}
/**
* Implementation of an {@link IActionError} that occurred in Darlean framework code while
* performing or trying to perform an action on an actor.
*/
class FrameworkError extends Error {
constructor(code, template, parameters, stack, nested, message) {
super(code);
this.kind = 'framework';
this.code = code;
this.parameters = parameters; // ? formatAllAttributes(parameters) : undefined;
this.template = template;
if (template === undefined) {
this.message = message ?? code;
}
else {
this.message = parameters ? (0, utils_1.replaceArguments)(template, parameters) : template;
}
if (haveStack(stack)) {
this.stack = stack;
}
this.nested = nested;
}
}
exports.FrameworkError = FrameworkError;