Skip to content

Commit 3cfac20

Browse files
committed
fix: 504 gateway timeout error for redis and mongo issues
1 parent 9235158 commit 3cfac20

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,15 @@ function errorHandler(
158158
err.message = translate(err.message);
159159
} else if (isErrorConstructorName(err, 'RedisError')) {
160160
// redis errors (e.g. ioredis' MaxRetriesPerRequestError)
161-
err.status = 408;
162-
err.message = translate(Boom.clientTimeout().output.payload.message);
161+
//
162+
// NOTE: we have to have 500 error here to prevent endless redirect loop
163+
//
164+
err.status = type === 'html' ? 504 : 408;
165+
err.message = translate(
166+
type === 'html'
167+
? Boom.gatewayTimeout().output.payload.message
168+
: Boom.clientTimeout().output.payload.message
169+
);
163170
} else if (passportLocalMongooseErrorNames.has(err.name)) {
164171
// passport-local-mongoose support
165172
if (!err.no_translate) err.message = translate(err.message);
@@ -179,8 +186,15 @@ function errorHandler(
179186
isErrorConstructorName(err, 'MongooseError')
180187
) {
181188
// parse mongoose (and mongodb connection errors)
182-
err.status = 408;
183-
err.message = translate(Boom.clientTimeout().output.payload.message);
189+
//
190+
// NOTE: we have to have 500 error here to prevent endless redirect loop
191+
//
192+
err.status = type === 'html' ? 504 : 408;
193+
err.message = translate(
194+
type === 'html'
195+
? Boom.gatewayTimeout().output.payload.message
196+
: Boom.clientTimeout().output.payload.message
197+
);
184198
} else if (
185199
// prevent code related bugs from
186200
// displaying to users in production environments

0 commit comments

Comments
 (0)