Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
front-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
front-backend
Commits
c9a8b708
Commit
c9a8b708
authored
Nov 15, 2020
by
ZhengJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[代码优化](v2.6):修复 responseType 为 blob 时无法解析后台返回的错误信息
close
https://github.com/elunez/eladmin/issues/524
parent
e310229f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
src/utils/request.js
+14
-10
No files found.
src/utils/request.js
View file @
c9a8b708
...
...
@@ -22,8 +22,6 @@ service.interceptors.request.use(
return
config
},
error
=>
{
// Do something with request error
console
.
log
(
error
)
// for debug
Promise
.
reject
(
error
)
}
)
...
...
@@ -31,17 +29,21 @@ service.interceptors.request.use(
// response 拦截器
service
.
interceptors
.
response
.
use
(
response
=>
{
const
code
=
response
.
status
if
(
code
<
200
||
code
>
300
)
{
Notification
.
error
({
title
:
response
.
message
})
return
Promise
.
reject
(
'error'
)
}
else
{
return
response
.
data
}
},
error
=>
{
// 兼容blob下载出错json提示
if
(
error
.
response
.
data
instanceof
Blob
&&
error
.
response
.
data
.
type
.
toLowerCase
().
indexOf
(
'json'
)
!==
-
1
)
{
const
reader
=
new
FileReader
()
reader
.
readAsText
(
error
.
response
.
data
,
'utf-8'
)
reader
.
onload
=
function
(
e
)
{
const
errorMsg
=
JSON
.
parse
(
reader
.
result
).
message
Notification
.
error
({
title
:
errorMsg
,
duration
:
5000
})
}
}
else
{
let
code
=
0
try
{
code
=
error
.
response
.
data
.
status
...
...
@@ -54,6 +56,7 @@ service.interceptors.response.use(
return
Promise
.
reject
(
error
)
}
}
console
.
log
(
code
)
if
(
code
)
{
if
(
code
===
401
)
{
store
.
dispatch
(
'LogOut'
).
then
(()
=>
{
...
...
@@ -78,6 +81,7 @@ service.interceptors.response.use(
duration
:
5000
})
}
}
return
Promise
.
reject
(
error
)
}
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment