feat: 添加令牌异常的处理

master
luoer 2023-08-07 17:44:11 +08:00
parent 6bdc589a6f
commit 450357a396
3 changed files with 28 additions and 0 deletions

Binary file not shown.

View File

@ -27,6 +27,26 @@ export class AllExecptionFilter implements ExceptionFilter {
);
}
// 令牌过期
if(exception.name === 'TokenExpiredError') {
return response.status(HttpStatus.UNAUTHORIZED).json(
Response.create({
code: ResponseCode.TOKEN_EXPIRED,
message: '登陆已过期'
})
)
}
// 令牌错误
if(exception.name === 'JsonWebTokenError') {
return response.status(HttpStatus.UNAUTHORIZED).json(
Response.create({
code: ResponseCode.TOKEN_ERORR,
message: '登陆令牌错误'
})
)
}
// 其他异常
response.status(HttpStatus.INTERNAL_SERVER_ERROR).json(
Response.create({

View File

@ -10,6 +10,14 @@ export enum ResponseCode {
*
*/
ERROR = 4000,
/**
*
*/
TOKEN_ERORR = 4050,
/**
*
*/
TOKEN_EXPIRED = 4051,
/**
*
*/