@@ -70,42 +70,41 @@ api.interceptors.response.use(
7070 * 规则是当 status 为 1 时表示请求成功,为 0 时表示接口需要登录或者登录状态失效,需要重新登录
7171 * 请求出错时 error 会返回错误信息
7272 */
73- if ( response . data . status === 1 ) {
74- if ( response . data . error !== '' ) {
75- toast . warning ( 'Warning' , {
76- description : response . data . error ,
77- } )
78- return Promise . reject ( response . data )
73+ if ( typeof response . data === 'object' ) {
74+ if ( response . data . status === 1 ) {
75+ if ( response . data . error !== '' ) {
76+ toast . warning ( 'Warning' , {
77+ description : response . data . error ,
78+ } )
79+ return Promise . reject ( response . data )
80+ }
7981 }
82+ else {
83+ useUserStore ( ) . requestLogout ( )
84+ }
85+ return Promise . resolve ( response . data )
8086 }
8187 else {
82- useUserStore ( ) . requestLogout ( )
88+ return Promise . reject ( response . data )
8389 }
84- return Promise . resolve ( response . data )
8590 } ,
8691 async ( error ) => {
8792 // 获取请求配置
8893 const config = error . config
89-
9094 // 如果配置不存在或未启用重试,则直接处理错误
9195 if ( ! config || ! config . retry ) {
9296 return handleError ( error )
9397 }
94-
9598 // 设置重试次数
9699 config . retryCount = config . retryCount || 0
97-
98100 // 判断是否超过重试次数
99101 if ( config . retryCount >= MAX_RETRY_COUNT ) {
100102 return handleError ( error )
101103 }
102-
103104 // 重试次数自增
104105 config . retryCount += 1
105-
106106 // 延迟重试
107107 await new Promise ( resolve => setTimeout ( resolve , RETRY_DELAY ) )
108-
109108 // 重新发起请求
110109 return api ( config )
111110 } ,
0 commit comments