express-mongoose-es6-rest-api icon indicating copy to clipboard operation
express-mongoose-es6-rest-api copied to clipboard

(err instanceof APIError) always returning false

Open skoope opened this issue 7 years ago • 4 comments

in config/express.js :

else if (!(err instanceof APIError)) {
    const apiError = new APIError(err.message, err.status, err.isPublic);
    return next(apiError);
  }

is supposed to catch errors that aren't instanceof APIError and convert them, but this always return false : example :

const err = new APIError('Not found', 404, true);
console.log(err instanceof APIError) // false
console.log(err instanceof Error) // true

skoope avatar Mar 27 '18 11:03 skoope

Which version of the boilerplate are you using?

kitce avatar Mar 29 '18 18:03 kitce

version 1.0.0

skoope avatar Mar 30 '18 10:03 skoope

I guess that's because of Babel.

You may need to use babel-plugin-transform-builtin-extend to make instanceof works as expected in Babel environment.

Take a look of this.

kitce avatar Mar 30 '18 10:03 kitce

I'll take a look at it ! thank you @kitce

skoope avatar Mar 30 '18 10:03 skoope