errors
errors copied to clipboard
Feature: message property templating
It would be nice to have the message string as a template against the other properties of the object... (suggest ES6 string template format, lodash has an implementation)
example:
errors.create({
name: 'DocumentNotFound',
message: 'The document "${document}" was not found.'
});
console.log(new errors.DocumentNotFound({ document: 'path/to/document.ext' }))
would output:
code: 6xx
name: 'DocumentNotFound'
message: 'The document "path/to/document.ext" was not found'
Idea burrowed from error/typed
//using lodash's _.template
...
if ((/\$\{[^\}]+\}/).test(this.message)) {
this.message = _.template(this.message, this);
}
} //end of constructor method
Making lodash a dependency without a version specified to allow for npm dedupe in a hosting package to always work, with a very slim risk of an incompatible version.
I'd add it myself, but the make/test setup doesn't work for me in windows (I'm at work).
@tracker1 - I will try to take a look at this in the next week (as time permits).
Obviously if you get time for PR - that's appreciated, but please include test coverage.
Thanks
@bodenr Does this enhancement added in the release?