@@ -10,9 +10,7 @@ const fastSafeStringify = require('fast-safe-stringify');
1010const humanize = require ( 'humanize-string' ) ;
1111const statuses = require ( 'statuses' ) ;
1212const toIdentifier = require ( 'toidentifier' ) ;
13- const { RedisError } = require ( 'redis-errors' ) ;
1413const { convert } = require ( 'html-to-text' ) ;
15- const MongooseError = require ( 'mongoose/lib/error' ) ;
1614
1715// lodash
1816const _isError = require ( 'lodash.iserror' ) ;
@@ -132,7 +130,7 @@ function errorHandler(
132130 // check if we threw just a status code in order to keep it simple
133131 err = Boom [ camelCase ( toIdentifier ( statuses . message [ val ] ) ) ] ( ) ;
134132 err . message = translate ( err . message ) ;
135- } else if ( err instanceof RedisError ) {
133+ } else if ( err . name === ' RedisError' ) {
136134 // redis errors (e.g. ioredis' MaxRetriesPerRequestError)
137135 err . status = 408 ;
138136 err . message = translate ( Boom . clientTimeout ( ) . output . payload ) ;
@@ -143,18 +141,16 @@ function errorHandler(
143141 err . status = 400 ;
144142 // 429 = too many requests
145143 if ( passportLocalMongooseTooManyRequests . has ( err . name ) ) err . status = 429 ;
146- } else if ( err . name === 'ValidationError' ) {
147- // parse mongoose validation errors
148- err = parseValidationError ( this , err , translate ) ;
149- } else if (
150- err instanceof MongooseError &&
151- ! ( err instanceof MongooseError . ValidationError ) &&
152- ! ( err instanceof MongooseError . ValidatorError ) &&
153- ! ( err instanceof MongooseError . VersionError )
154- ) {
144+ } else if ( err . name === 'MongooseError' ) {
155145 // parse mongoose (and mongodb connection errors)
156146 err . status = 408 ;
157147 err . message = translate ( Boom . clientTimeout ( ) . output . payload ) ;
148+ } else if (
149+ err . name === 'ValidationError' &&
150+ Object . getPrototypeOf ( err . constructor ) . name === 'MongooseError'
151+ ) {
152+ // parse mongoose validation errors
153+ err = parseValidationError ( this , err , translate ) ;
158154 }
159155
160156 // check if we have a boom error that specified
0 commit comments