shutterstock / node-common-errors

Common error classes and utility functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to customize the error messages?

erapoport opened this issue · comments

I find this very long - "An attempt was made to perform an operation that is invalid", especially because it seems the wrong message for NotPermittedError.

I know I can create my own classes, but the whole point for me is to have your thought-out list of errors, not the ability to create my own per-se.

So I thought to ask if that part of the error can be easily customized.

Thanks!

Yes, of course. You can override the generateMessage method on the prototype.
That being said, the constructor allows you to append a clarifying message simply by passing a string to the constructor.

What could you suggest for a revised message?

Something about being not permitted :)

Thanks, I'll try with generateMessage

This is what I did:

errors.NotPermittedError.prototype.generateMessage = function ()
{
      return "Operation not permitted: " + this.message;
};

I don't know enough about ES6 scoping to understand why the exact same thing doesn't work with () =>, it says this is undefined :-\

Thanks, it was really easy 👍