Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for error causes/chaining with a custom message to HTTP exceptions #10392

Closed
1 task done
nathan-knight opened this issue Oct 10, 2022 · 2 comments
Closed
1 task done
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@nathan-knight
Copy link
Contributor

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

#9705 added some support for error causes but it does not allow you to provide a custom message along with a cause (the PR description points this out).

Describe the solution you'd like

I'd like there to be a 3rd parameter added to HttpException that mirrors the options object in Node as of 16.9.0: https://nodejs.org/docs/latest-v16.x/api/errors.html#new-errormessage-options and an additional parameter for the other exceptions, this way we can pass in a custom message like normal while specifying a cause.

Many (or all) of the exceptions have an optional second string parameter for the description so in order to allow that to be optional while specifying the options object, it can be distinguished by whether or not a string is passed for the second option, if it is an object then we know it's the options object and not a description and the default should be used.

Teachability, documentation, adoption, migration strategy

It should be backwards compatible and the fact that it is the same as the default from Node now means that it should be easy to understand for developers.

What is the motivation / use case for changing the behavior?

We often handle an error and want to add a new message to it without losing the information from the original error. The current implementation lets us add an error as the cause but it needs to be the first parameter which means we cannot add any custom information there. With this change we can have the best of both worlds and make full use of error causes/chaining along with the rest of the functionality that NestJS exceptions provide.

@nathan-knight nathan-knight added needs triage This issue has not been looked into type: enhancement 🐺 labels Oct 10, 2022
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@thiagomini
Copy link
Contributor

Should we close this, @kamilmysliwiec?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

4 participants