Hey,
here's what I monkey-patched in my project that is using node-api-problem:
// monkey patching 🐒
ApiProblem.prototype.toJSON = function toJSON () {
const obj = {};
for (const key in this) {
if ({}.hasOwnProperty.call(this, key) && key !== 'confidential') {
obj[key] = this[key];
}
}
return obj;
};
Here's my motivation:
There are two way's the backend reports errors:
- to the user, using
res.send(err.toJSON());, etc.
- to our internal error reporting
both of these have a different purpose / detail level, e.g.
- the consumer of the API will only get to know that something went wrong, some details that could help with debugging, but it's mostly very sparse and with generic error messages
- the internal reporting has lots of details, i. e. what went wrong, why, the causing error, the log level, the user record, request id, extra debugging data, etc.
Using the above monkey patch, we store the confidential information inside the ApiProblem instance from the moment that instance is created and are able to do the error reporting / logging in the express middleware.
Could node-api-problem support the use case described above without the need for a monkey patch ?
Hey,
here's what I monkey-patched in my project that is using
node-api-problem:Here's my motivation:
There are two way's the backend reports errors:
res.send(err.toJSON());, etc.both of these have a different purpose / detail level, e.g.
Using the above monkey patch, we store the confidential information inside the
ApiProbleminstance from the moment that instance is created and are able to do the error reporting / logging in the express middleware.Could
node-api-problemsupport the use case described above without the need for a monkey patch ?