Feature: Basic Events, Models and Projections #2

Merged
piarrot merged 37 commits from feat-base-projections into main 2024-10-15 15:20:25 -03:00
2 changed files with 6 additions and 10 deletions
Showing only changes of commit 7a56c34941 - Show all commits

View File

@ -3,14 +3,15 @@ import { TaggedVariant, VariantTag } from "../variant/index.js";
/**
* A TaggedError is a tagged variant with an error message.
*/
export class TaggedError<Tag extends string = string>
export abstract class TaggedError<Tag extends string = string>
extends Error
implements TaggedVariant<Tag>
{
readonly [VariantTag]: Tag;
constructor(tag: Tag) {
super();
constructor(tag: Tag, message?: string) {
super(message);
this[VariantTag] = tag;
this.name = tag;
}
}

View File

@ -8,12 +8,7 @@ import { TaggedError } from "./tagged-error.js";
* we must be prepared to handle.
*/
export class UnexpectedError extends TaggedError<"UnexpectedError"> {
constructor(readonly context: Record<string, unknown> = {}) {
super("UnexpectedError");
this.message = "An unexpected error occurred";
}
toString() {
return `UnexpectedError: ${this.message}\n${JSON.stringify(this.context, null, 2)}`;
constructor(message?: string) {
super("UnexpectedError", message);
}
}