From 86ca3735de93c9b37094d359321b128e6477c57f Mon Sep 17 00:00:00 2001 From: shaodahong Date: Wed, 10 Jun 2020 15:14:40 +0800 Subject: [PATCH] fix: httpConsole reject error message --- lib/httpConsole.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/httpConsole.ts b/lib/httpConsole.ts index 052dc33..270e20b 100644 --- a/lib/httpConsole.ts +++ b/lib/httpConsole.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import axios, { AxiosError } from 'axios'; import Cookie from 'js-cookie'; import { clearConsoleCookie, clearConsoleToken, getConsoleToken, toConsoleLogin } from './token'; @@ -146,9 +146,11 @@ httpConsole.interceptors.response.use( // reject错误处理 return Promise.reject(new HttpError(data.resMsg || data.msg || data.message, data)); }, - error => { + (error: AxiosError) => { console.error('http:reject', error); // reject错误处理 - return Promise.reject(new HttpError('系统错误')); + const { data } = error.response || {}; + const { message = '系统错误', msg, resMsg } = data || {}; + return Promise.reject(new HttpError(resMsg || msg || message)); }, );