Skip to content

feat: support new Error.cause property #6

@petermetz

Description

@petermetz

It would be great if this library could pass the cause property down to the underlying (sub-classed) built-in Error constructor so that something like this works:

const cause = new Error("Something went wrong and this is the root cause");
throw new InternalServerError("An internal error occurred.", { cause });

In comparison if you write this code it will print the screenshot below (that's the expected behavior that would be great to get from this library as well):

const cause = new Error("Something went wrong and this is the root cause");
throw new Error("An internal error occurred.", { cause });

image

I believe all it needs is for the properties to be passed in at this line in base.ts:

    // Assign basic properties
    super(message as string)

https://github.com/ShogunPanda/http-errors-enhanced/blob/main/src/base.ts#L41

image

https://github.com/tc39/proposal-error-cause

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions