lambda-api
lambda-api copied to clipboard
Error type names are not preserved when using code bundlers
trafficstars
When using lambda-api together with some code bundler like rollup class names are rewritten to avoid duplicates.
The class RouteError will for example be rewritten to something like this:
class RouteError$1 extends Error {
constructor(message, path) {
super(message);
this.name = this.constructor.name;
this.path = path;
}
}
The use of this.name = this.constructor.name will make it so that error.name will be "RouteError$1" and not "RouteError"
The result of this is that you can't use the error.name property to check for the error type like mentioned in the docs
Instead you'll have to do some workaround like this:
if (err.name.includes('RouteError')) {
// do something with route error
}
Proposed solution
Simply set the error name to a static string to ensure that it's always the same, like this:
this.name = 'RouteError'