update 手动抛出的异常返回的code仍然为200
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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 }) => {
|
||||||
|
|||||||
@@ -222,31 +222,33 @@ export default class QueryTable extends Component {
|
|||||||
this.query = this.props.queryInitialValues
|
this.query = this.props.queryInitialValues
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await this.loadData(
|
try {
|
||||||
{
|
const res = await this.loadData(
|
||||||
pageIndex: this.pagination.current,
|
{
|
||||||
pageSize: this.pagination.pageSize,
|
pageIndex: this.pagination.current,
|
||||||
...this.sorter,
|
pageSize: this.pagination.pageSize,
|
||||||
},
|
...this.sorter,
|
||||||
cloneDeep(this.query)
|
},
|
||||||
)
|
cloneDeep(this.query)
|
||||||
if (res.rows || res.data || res.items) {
|
)
|
||||||
this.setState({
|
if (res.rows || res.data || res.items) {
|
||||||
type: 'table',
|
this.setState({
|
||||||
dataSource: res.rows || res.data || res.items,
|
type: 'table',
|
||||||
})
|
dataSource: res.rows || res.data || res.items,
|
||||||
|
})
|
||||||
|
|
||||||
this.pagination.total = res.totalCount
|
this.pagination.total = res.totalCount
|
||||||
} else if (res) {
|
} else if (res) {
|
||||||
this.setState({
|
this.setState({
|
||||||
type: 'tree',
|
type: 'tree',
|
||||||
dataSource: clearChildren(res),
|
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('登录成功')
|
Message.success('登录成功')
|
||||||
this.props.history.replace('/')
|
this.props.history.replace('/')
|
||||||
} else {
|
} else {
|
||||||
|
this.setState({ loading: false })
|
||||||
Message.error(message)
|
Message.error(message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user