update 手动抛出的异常返回的code仍然为200
This commit is contained in:
@@ -41,6 +41,20 @@ namespace Ewide.Core
|
||||
// 解析异常信息
|
||||
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>
|
||||
{
|
||||
Code = StatusCode,
|
||||
|
||||
@@ -13,7 +13,7 @@ import status from './status'
|
||||
* api.getItemGroupType(parmas).then(...)
|
||||
*/
|
||||
import urls from './requests'
|
||||
import { notification } from 'antd'
|
||||
import { message as Message, notification } from 'antd'
|
||||
|
||||
const STATUS = status
|
||||
|
||||
@@ -64,6 +64,10 @@ const errorNotification = ({ code, message }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const errorMessage = (message) => {
|
||||
Message.error(message)
|
||||
}
|
||||
|
||||
const handlerUnauthorized = () => {
|
||||
token.value = ''
|
||||
window.location.replace('/login')
|
||||
@@ -125,13 +129,28 @@ for (let key in urls) {
|
||||
api[`${key}Await`](params)
|
||||
.then((res) => {
|
||||
const { data } = res
|
||||
const isFile = [ArrayBuffer, Blob].includes(data.constructor)
|
||||
const result = isFile ? res : data
|
||||
|
||||
// 错误的返回码,以通知的形式弹出
|
||||
if (errerCodes.indexOf(data.code) >= 0) {
|
||||
errorNotification(data)
|
||||
reject([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data)
|
||||
} else if (data.code === STATUS.Unauthorized) {
|
||||
reject(result)
|
||||
}
|
||||
|
||||
// 非文件,返回码正确,但是结果失败,以消息的形式弹出
|
||||
else if (!isFile && !data.success) {
|
||||
errorMessage(data.message)
|
||||
reject(result)
|
||||
}
|
||||
|
||||
// 未登录
|
||||
else if (data.code === STATUS.Unauthorized) {
|
||||
handlerUnauthorized()
|
||||
} else {
|
||||
reslove([ArrayBuffer, Blob].indexOf(data.constructor) > -1 ? res : data)
|
||||
}
|
||||
|
||||
else {
|
||||
reslove(result)
|
||||
}
|
||||
})
|
||||
.catch(({ response }) => {
|
||||
|
||||
@@ -222,31 +222,33 @@ export default class QueryTable extends Component {
|
||||
this.query = this.props.queryInitialValues
|
||||
}
|
||||
|
||||
const res = await this.loadData(
|
||||
{
|
||||
pageIndex: this.pagination.current,
|
||||
pageSize: this.pagination.pageSize,
|
||||
...this.sorter,
|
||||
},
|
||||
cloneDeep(this.query)
|
||||
)
|
||||
if (res.rows || res.data || res.items) {
|
||||
this.setState({
|
||||
type: 'table',
|
||||
dataSource: res.rows || res.data || res.items,
|
||||
})
|
||||
try {
|
||||
const res = await this.loadData(
|
||||
{
|
||||
pageIndex: this.pagination.current,
|
||||
pageSize: this.pagination.pageSize,
|
||||
...this.sorter,
|
||||
},
|
||||
cloneDeep(this.query)
|
||||
)
|
||||
if (res.rows || res.data || res.items) {
|
||||
this.setState({
|
||||
type: 'table',
|
||||
dataSource: res.rows || res.data || res.items,
|
||||
})
|
||||
|
||||
this.pagination.total = res.totalCount
|
||||
} else if (res) {
|
||||
this.setState({
|
||||
type: 'tree',
|
||||
dataSource: clearChildren(res),
|
||||
})
|
||||
this.pagination.total = res.totalCount
|
||||
} else if (res) {
|
||||
this.setState({
|
||||
type: 'tree',
|
||||
dataSource: clearChildren(res),
|
||||
})
|
||||
|
||||
this.pagination = false
|
||||
this.pagination = false
|
||||
}
|
||||
} finally {
|
||||
this.onLoaded()
|
||||
}
|
||||
|
||||
this.onLoaded()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ export default class index extends Component {
|
||||
Message.success('登录成功')
|
||||
this.props.history.replace('/')
|
||||
} else {
|
||||
this.setState({ loading: false })
|
||||
Message.error(message)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user