update 手动抛出的异常返回的code仍然为200

This commit is contained in:
2021-06-30 11:54:23 +08:00
parent 35cb452d09
commit 635dd52270
4 changed files with 63 additions and 27 deletions

View File

@@ -41,6 +41,20 @@ namespace Ewide.Core
// 解析异常信息 // 解析异常信息
var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context); var (StatusCode, ErrorCode, Errors) = UnifyContext.GetExceptionMetadata(context);
// 如果是代码自行抛出的异常,视为接口调用成功,返回结果失败
if (context.Exception.GetType() == typeof(Furion.FriendlyException.AppFriendlyException))
{
return DisplayJson(new RestfulResult<object>
{
Code = StatusCodes.Status200OK,
Success = false,
Data = null,
Message = Errors,
Extras = UnifyContext.Take(),
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});
}
return DisplayJson(new RestfulResult<object> return DisplayJson(new RestfulResult<object>
{ {
Code = StatusCode, Code = StatusCode,

View File

@@ -13,7 +13,7 @@ import status from './status'
* api.getItemGroupType(parmas).then(...) * api.getItemGroupType(parmas).then(...)
*/ */
import urls from './requests' import urls from './requests'
import { notification } from 'antd' import { message as Message, notification } from 'antd'
const STATUS = status const STATUS = status
@@ -64,6 +64,10 @@ const errorNotification = ({ code, message }) => {
} }
} }
const errorMessage = (message) => {
Message.error(message)
}
const handlerUnauthorized = () => { const handlerUnauthorized = () => {
token.value = '' token.value = ''
window.location.replace('/login') window.location.replace('/login')
@@ -125,13 +129,28 @@ for (let key in urls) {
api[`${key}Await`](params) api[`${key}Await`](params)
.then((res) => { .then((res) => {
const { data } = res const { data } = res
const isFile = [ArrayBuffer, Blob].includes(data.constructor)
const result = isFile ? res : data
// 错误的返回码,以通知的形式弹出
if (errerCodes.indexOf(data.code) >= 0) { if (errerCodes.indexOf(data.code) >= 0) {
errorNotification(data) errorNotification(data)
reject([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data) reject(result)
} else if (data.code === STATUS.Unauthorized) { }
// 非文件,返回码正确,但是结果失败,以消息的形式弹出
else if (!isFile && !data.success) {
errorMessage(data.message)
reject(result)
}
// 未登录
else if (data.code === STATUS.Unauthorized) {
handlerUnauthorized() handlerUnauthorized()
} else { }
reslove([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data)
else {
reslove(result)
} }
}) })
.catch(({ response }) => { .catch(({ response }) => {

View File

@@ -222,6 +222,7 @@ export default class QueryTable extends Component {
this.query = this.props.queryInitialValues this.query = this.props.queryInitialValues
} }
try {
const res = await this.loadData( const res = await this.loadData(
{ {
pageIndex: this.pagination.current, pageIndex: this.pagination.current,
@@ -245,9 +246,10 @@ export default class QueryTable extends Component {
this.pagination = false this.pagination = false
} }
} finally {
this.onLoaded() this.onLoaded()
} }
}
/** /**
* 数据开始加载 * 数据开始加载

View File

@@ -36,6 +36,7 @@ export default class index extends Component {
Message.success('登录成功') Message.success('登录成功')
this.props.history.replace('/') this.props.history.replace('/')
} else { } else {
this.setState({ loading: false })
Message.error(message) Message.error(message)
} }
}) })