feat: validateOrReject should throw instance of Error
See original GitHub issuevalidateOrReject
throws an array of errors that does not have a stack.
That is bad in case such error is not being caught and results in 500 Internal Server Error.
Is it possible to add something like validateOrError
that would throw an instance like this instead:
class ObjectInvalid extends Error {
errors: ValidationError[]
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (9 by maintainers)
Top Results From Across the Web
How to test the type of a thrown exception in Jest
Really like this one as my code needs to test a value of the thrown error so I need the instance. I would...
Read more >How to use the class-validator.validateOrReject function in ...
validateOrReject examples, based on popular ways it is used in public projects. ... await validateOrReject(validation) } catch (error) { throw new this.
Read more >Better error handling in JavaScript | by Iain Collins - Medium
It's best to avoid throwing errors from inside a Promise, because they may not always be caught, depending on how the code that...
Read more >npm:aws-lambda-framework | Skypack
Errors are automatically logged and optionally send to a Slack channel of your choice. New Lambda functions must implement an invoke function, which...
Read more >Basic Error Handling with Exceptions | C# Methods ... - InformIT
For example, assume the user enters “forty-two” for the age in the previous example. In this case, int.Parse() will throw an exception of ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure why not. Let’s introduce new
validateOrThrow
method and markvalidateOrReject
as deprecated.Not all of the rejects are being caught and processed. It means that if the error is displayed in console or sent to exception notification software, you will have no error stack available.
Example jest error when
validateOrReject
throws:You may see that jest can only tell the test where the error occurred not the line number and backtrace.
When you see something like this in console:
You have no idea where to fix it.
Any linter will tell you that throwing something that doesn’t inherit
Error
class is a bad idea:https://palantir.github.io/tslint/rules/no-string-throw/ https://eslint.org/docs/rules/no-throw-literal
BTW, this is first time I see someone throws an Array. IMO it is even more terrible idea than throwing a string because when you see it in console you don’t even realize what had happened.