我正在尝试打印来自SpringBoot验证的错误。 我收到的回复是:
{status: "BAD_REQUEST",…}
status: "BAD_REQUEST"
message: "Validation failed for argument [0] (...) on field 'inConsultaDocumento': rejected value []; codes [NotBlank.emissorRaizFilialForm.inConsultaDocumento,NotBlank.inConsultaDocumento,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [emissorRaizFilialForm.inConsultaDocumento,inConsultaDocumento]; arguments []; default message [inConsultaDocumento]]; default message [A consulta do documento deve ser preenchida!]] "
errors: ["A consulta do documento deve ser preenchida!"]
0: "A consulta do documento deve ser preenchida!"
我正在使用axiosAuth以此方式调用后端:
axiosAuth.post(url, emissorFilial, getConfig())
.then(response =>{
console.log("success", response.data);
this.setState({
alert: {
visible: true,
message: response.data.retorno,
level: response.data.success ? "success" : "danger"
}
})
}).catch(error => {
console.log(error)
});
}
export const getConfig = (params, contentType) => {
const userId = getCookie(COOKIE_USER_ID);
const userToken = getCookie(COOKIE_USER_TOKEN);
if (contentType == null || contentType == '') contentType = 'application/json; charset=utf-8';
return {
headers: {
'Accept': 'application/json',
'Authorization': 'Basic ' + API_KEY,
'X-B2W-UserId': userId,
'X-b2w-token': userToken,
'X-B2W-System': SYSTEM,
'Content-Type': contentType
},
params: params
}
}
但是我无法访问错误数组。我收到以下消息:
Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:59)
我想打印以下消息:“进行文档咨询!”。
为什么我无法访问此消息?