Skip to content

Commit 0248297

Browse files
committed
Improve rate limit error case
Returns a plain string error like the rest of the API, and adds CORS headers so that's available on the web.
1 parent bba9f55 commit 0248297

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

api/src/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ apiRouter.use((req, _res, next) => {
9090
const RATE_LIMIT_PARAMS = {
9191
max: 10,
9292
windowMs: 60 * 60 * 1000, // 1h window
93-
message: { error: 'Too many login attempts, please try again after 1 hour' },
93+
handler: (req: express.Request, res: express.Response) => {
94+
res.status(429)
95+
.set(getCorsResponseHeaders(
96+
convertReqToLambdaEvent(req),
97+
{ allowAnyOrigin: true }
98+
))
99+
.send('Too many login attempts, please try again after 1 hour');
100+
},
94101
standardHeaders: true,
95102
legacyHeaders: false
96103
};

0 commit comments

Comments
 (0)