fix: handle token errors in front service (#8336)

This commit is contained in:
Alexander Onnikov 2025-03-25 13:22:20 +07:00 committed by GitHub
parent edda71fef4
commit b84d839a01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -525,6 +525,10 @@ export function start (
)
}
} catch (error: any) {
if (error instanceof TokenError) {
res.status(401).send()
return
}
if (
error?.code === 'NoSuchKey' ||
error?.code === 'NotFound' ||
@ -633,6 +637,10 @@ export function start (
res.status(200).send()
} catch (error: any) {
if (error instanceof TokenError) {
res.status(401).send()
return
}
Analytics.handleError(error)
ctx.error('failed to delete', { url: req.url })
res.status(500).send()

View File

@ -45,7 +45,11 @@ export function generateToken (
* @public
*/
export function decodeToken (token: string, verify: boolean = true, secret?: string): Token {
return decode(token, secret ?? getSecret(), !verify)
try {
return decode(token, secret ?? getSecret(), !verify)
} catch (err: any) {
throw new TokenError(err.message)
}
}
/**