From 450357a396f9c3d811db5a7256d11ce75a7745d0 Mon Sep 17 00:00:00 2001 From: luoer <952222@163.com> Date: Mon, 7 Aug 2023 17:44:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BB=A4=E7=89=8C?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/database/db.sqlite | Bin 147456 -> 147456 bytes src/common/response/notcaptured.filter.ts | 20 ++++++++++++++++++++ src/common/response/response.code.ts | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/content/database/db.sqlite b/content/database/db.sqlite index c01e16ed89d359231449dba763bb7c7803d78208..9b8165788bf90a1e002e9c4d6361ecaa20b61cca 100644 GIT binary patch delta 396 zcmZo@;B08%oFL7pJyFJ)QF~)TlRl%w=EwSS1-#q`8JL-q7`Q*NPhw8mEGQ7dyg8{j zo`Z#ffx&R{(P~|u4sJ$X24f&(U{IZWu3ACNT*1K1%Gkil$o$#X?icH)KAYD5eD#86 zlQr8-)-axJ7Uew8z|N7xz-P|W%(a$Fi{m0^2nWby9}cEmiRl+DnZ#v*MwnU|n^+lI z8W|WF>l#?-8X$zGvsy7(ay2rD@qw*1o_@oUNg1NW$i&LP1XT-I2&~1gQXHy-K~OlF zL6QMkp^=rbnU#q#vXH42NUtFlp%fr6oGxg^qzej$=;@a&nZgAd8AM^mOG<)_pPp#N YB&>#}9q27|6G1{?2X0?$#T3j605PLn2><{9 delta 144 zcmZo@;B08%oFL7pGEv5vQDtL7lRl%^=EwSS1-uLl49v_)4BQ9VCov~&78D3!-ken2 zz|;I_{q{%e8RZ)UfeKhT&ol6u^E7j<<+9^E4^*_5lQUP0kHHuS8K&R1U{ap`+mcCt ox`QQ?2xqP+Ov1#9Ntw$~!NAnY#K_9Xc)GMDljZicR!qUH058)e2mk;8 diff --git a/src/common/response/notcaptured.filter.ts b/src/common/response/notcaptured.filter.ts index 90d9041..05a1a98 100644 --- a/src/common/response/notcaptured.filter.ts +++ b/src/common/response/notcaptured.filter.ts @@ -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({ diff --git a/src/common/response/response.code.ts b/src/common/response/response.code.ts index 0fbc4c8..63e8002 100644 --- a/src/common/response/response.code.ts +++ b/src/common/response/response.code.ts @@ -10,6 +10,14 @@ export enum ResponseCode { * 客户端未知错误 */ ERROR = 4000, + /** + * 令牌错误 + */ + TOKEN_ERORR = 4050, + /** + * 登陆过期 + */ + TOKEN_EXPIRED = 4051, /** * 参数错误 */