File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @ethan-utils/axios " : patch
3+ ---
4+
5+ 优化未授权验证插件
Original file line number Diff line number Diff line change @@ -6,20 +6,20 @@ export interface UnauthorizedOptions {
66 */
77 onUnauthorized ?: ( ) => void ;
88 /**
9- * 触发未授权回调的响应数据中的 code 值,默认为 401
9+ * 触发未授权回调的响应数据中的 code 值,默认为 1001
1010 */
1111 unauthorizedCodes ?: number | number [ ] ;
1212}
1313
1414/**
1515 * 未授权处理插件
16- * 支持检测 HTTP 状态码 401 和响应数据中的自定义 code 值
16+ * 支持检测 HTTP 状态码 401 和 403 以及响应数据中的自定义 code 值
1717 */
1818export function unauthorizedPlugin (
1919 api : AxiosInstance ,
2020 options : UnauthorizedOptions = { } ,
2121) {
22- const { onUnauthorized, unauthorizedCodes = 401 } = options ;
22+ const { onUnauthorized, unauthorizedCodes = 1001 } = options ;
2323
2424 if ( ! onUnauthorized ) {
2525 return ;
@@ -40,9 +40,9 @@ export function unauthorizedPlugin(
4040 return response ;
4141 } , undefined ) ;
4242
43- // 错误响应拦截器 - 检查 HTTP 状态码 401
43+ // 错误响应拦截器 - 检查 HTTP 状态码 401 或 403
4444 api . interceptors . response . use ( undefined , ( error : AxiosError ) => {
45- if ( error . response ?. status === 401 ) {
45+ if ( error . response ?. status === 401 || error . response ?. status === 403 ) {
4646 onUnauthorized ( ) ;
4747 }
4848 return Promise . reject ( error ) ;
You can’t perform that action at this time.
0 commit comments