feat: 添加令牌异常的处理
parent
6bdc589a6f
commit
450357a396
Binary file not shown.
|
|
@ -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.status(HttpStatus.INTERNAL_SERVER_ERROR).json(
|
||||||
Response.create({
|
Response.create({
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,14 @@ export enum ResponseCode {
|
||||||
* 客户端未知错误
|
* 客户端未知错误
|
||||||
*/
|
*/
|
||||||
ERROR = 4000,
|
ERROR = 4000,
|
||||||
|
/**
|
||||||
|
* 令牌错误
|
||||||
|
*/
|
||||||
|
TOKEN_ERORR = 4050,
|
||||||
|
/**
|
||||||
|
* 登陆过期
|
||||||
|
*/
|
||||||
|
TOKEN_EXPIRED = 4051,
|
||||||
/**
|
/**
|
||||||
* 参数错误
|
* 参数错误
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue