Created
March 11, 2021 17:42
-
-
Save davixz/5046918350800e220154e9718e6a11b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can use throw new Error() normally | |
throw new Error('My error message'); | |
You can give a id to the error like so | |
let error = new Error('My error message'); | |
error.name = 'my_error_id'; | |
throw error; | |
The stack trace is preserved | |
If you dont catch the exception, this will translate into a single error in the response error list with the message you passed to Error() | |
This will produce a 500 status response | |
Additionaly You can use our CustomError with the function _Error() like so | |
throw new _Error({ message: 'My error message', id: 'my_error_id' }); | |
throw new _Error({ message: 'My error message', id: 'my_error_id', status: 400 }); | |
throw new _Error({ message: 'My error message', id: 'my_error_id', status: 400, data: { key: 'value'} }); | |
throw new _Error({ message: 'My error message', id: 'my_error_id', status: 400, data: { key: 'value'}, data_raw: { key: 'value'} }); | |
If you provide the status property We will set the response status for you like 400 in the examples |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment