Closed a-game closed 1 year ago
I encountered a similar issue with esbuild
where the name attributes are stripped from classes when minimized. I don't know if the linked PR will solve the problem but I propose exporting the error classes instead. So ideally we can do class checking instead of name checking
import { RouteError } from 'lambda-api'
if( err instanceof RouteError ) {
// Handle route error
}
if anything the exporting of the error might be a bug because the error types are defined in index.d.ts but they are not really exported from the main entry file. If you would use the strategy above then RouteError
will be undefined at runtime because it Is just a type reference that your editor can pick up.
When using
lambda-api
together with some code bundler likerollup
class names are rewritten to avoid duplicates.The class
RouteError
will for example be rewritten to something like this:The use of
this.name = this.constructor.name
will make it so thaterror.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 docsInstead you'll have to do some workaround like this:
Proposed solution
Simply set the error name to a static string to ensure that it's always the same, like this:
this.name = 'RouteError'