Skip to content

Error type names are not preserved when using code bundlers #204

@a-game

Description

@a-game

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions