|
@@ -14,7 +14,7 @@ export class AjaxError extends Error {
|
|
|
// const RESPONSE_ERROR = 'ResponseError'
|
|
|
const REQUEST_CANCEL = 'RequestCancel'
|
|
|
|
|
|
-export default (baseApiPath) => {
|
|
|
+export default (baseApiPath, onError) => {
|
|
|
const link = document.createElement('a')
|
|
|
|
|
|
const request = axios.create({
|
|
@@ -62,6 +62,16 @@ export default (baseApiPath) => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if (typeof onError === 'function') {
|
|
|
+ const { response } = error
|
|
|
+ if (response) {
|
|
|
+ const { data } = response
|
|
|
+ if (data && data.type === 'failure') {
|
|
|
+ onError(data.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (!(error instanceof AjaxError)) {
|
|
|
error = new AjaxError('服务器正忙', 500)
|
|
|
}
|