【发布时间】:2020-04-29 09:09:54
【问题描述】:
在抛出异常(Java 中的服务器)时,我无法看到设置的消息(在 React.js 的 catch 块中)。
情况: 用户想要执行一些操作(通过 myService),一些验证 w.r.t 操作只能在后端完成,如果失败如何向用户显示失败的原因?
服务(Java):
@GetMapping(path = {/*Servive_path*/}, produces = APPLICATION_JSON_VALUE)
public MyClass myService(@RequestParam String param) {
throw new RuntimeException("This is error message");
}
动作(React.js):
const myServive = (param) => {
return async (dispatch, getState) => {
return request({
url: ENDPOINTS.MY_SERVICE,
method: methods.GET,
params: { param }
})
.then(res => {
dispatch(saveResult(res));
dispatch(
notify({
title: "Successful",
message: "It was successfully.",
status: 200,
dismissAfter: CONFIG.NOTIFICATION_TIMEOUT
})
);
})
.catch(err => {
console.log("err.data: ", err.data); //Output-> err.data:
console.log("err.message: ", err.message); //Output-> err.message: undefined
dispatch(
notify({
title: "Some error occured",
message: **//Want to set the error message**,
status: "error",
dismissAfter: CONFIG.NOTIFICATION_TIMEOUT
})
);
});
};
};
希望通过在 catch 动作块中设置按摩值来显示异常消息。
输出
err.data: ""
err.message: undefined
还有,
err.status: 500
err.request.response: ""
err.request.responseText: ""
err.request.responseType: ""
err.request.status: 500
err.request.statusText: ""
请帮忙。
【问题讨论】:
-
这可能是同一个问题吗? stackoverflow.com/questions/43800998/…
标签: java reactjs spring rest react-redux