catch authorization error in rate limiter and 5 rpm

This commit is contained in:
Hongbo Wu 2023-06-28 17:04:47 +08:00
parent b7c133d58e
commit 74f2dd6bf1

View file

@ -103,8 +103,13 @@ export const createApp = (): {
max: async (req) => {
// 100 RPM for an authenticated request, 5 for a non-authenticated request
const token = getTokenByRequest(req)
const claims = await getClaimsByToken(token)
return claims ? 100 : 5
try {
const claims = await getClaimsByToken(token)
return claims ? 100 : 5
} catch (e) {
console.log('non-authenticated request')
return 5
}
},
keyGenerator: (req) => {
return getTokenByRequest(req) || req.ip