fetch 异常处理
parent
49433609d1
commit
64010ff9c8
|
@ -158,6 +158,21 @@
|
||||||
return !isBlank(obj)
|
return !isBlank(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkStatus(response) {
|
||||||
|
if (response.status >= 200 && response.status < 300) {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const error = new Error(response.statusText);
|
||||||
|
error.response = response
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJSON(response) {
|
||||||
|
return response.json()
|
||||||
|
}
|
||||||
|
|
||||||
const data = () => {
|
const data = () => {
|
||||||
return {
|
return {
|
||||||
auditForm: {
|
auditForm: {
|
||||||
|
@ -262,19 +277,24 @@
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(form),
|
body: JSON.stringify(form),
|
||||||
}).then(res => res.json())
|
}).then(checkStatus).then(parseJSON).then(data => {
|
||||||
.then(data => {
|
this.page = {
|
||||||
this.page = {
|
data: data.content,
|
||||||
data: data.content,
|
size: data.size,
|
||||||
size: data.size,
|
current: data.number + 1,
|
||||||
current: data.number + 1,
|
total: data.totalElements
|
||||||
total: data.totalElements
|
}
|
||||||
}
|
}).catch(({ response }) => {
|
||||||
})
|
if (response) {
|
||||||
.catch(err => {
|
parseJSON(response)
|
||||||
this.$message.error('查询失败');
|
.then(json => {
|
||||||
})
|
this.$message.error(json.message || "查询失败")
|
||||||
.finally(() => loading.close())
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.$message.error("查询失败")
|
||||||
|
}
|
||||||
|
}).finally(() => loading.close())
|
||||||
},
|
},
|
||||||
|
|
||||||
handlePageChange(val) {
|
handlePageChange(val) {
|
||||||
|
|
Loading…
Reference in New Issue