-
Notifications
You must be signed in to change notification settings - Fork 30
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
How to change the default error output in restify 7.x? #93
Comments
It seems that the docs are wrong,
|
Restify-errors 7.x makeConstructor doesn't work, I use it normally in 5.x. You can install Restify 7.2.1. |
in older versions the plugin add the constructor, in this version you need add manually
|
Hi all - what version of restify-errors are you using? This should work on latest 7.0.0 release: const errs = require('restify-errors');
const MyErr = errs.makeConstructor('MyError');
throw new MyErr('boom');
Regarding the storing of classes on the exports of the module, that feature was removed in 6.x. Some additional context can be found here: |
I changed the default error output in restify 4.x using the below code
`var restify = require('restify');
var util = require('util');
function ValidationError(message, errors) {
restify.RestError.call(this, {
restCode: 'ValidationError',
statusCode: 400,
message: message,
constructorOpt: ValidationError
});
this.name = 'ValidationError';
this.body.errors = errors; //<---
}
util.inherits(ValidationError, restify.RestError);`
And I got the desired result. Now am in a process of migrating my project to restify 7.x. So I couldn't use the restify.RestError, I have tried 'restify-errors-options' package's subclassing property but it doesn't work for me. I have tried the below code
restifyErrors.makeConstructor('ValidationError', { restCode: 'ValidationError', statusCode: 400, message: message }); var myErr = new errors.ValidationError( );
And I ended up with the below error
So can anyone suggest a solution for this problem?
The text was updated successfully, but these errors were encountered: