从 AXIOS 中的 post 请求获取错误处理程序数据
Getting error handler data from post request in AXIOS
你能告诉我如何在 axios 中使用来自 post 类型请求的响应,它会给出错误 422(无法处理的实体)吗?我无法使用来自 API 的 JSON 响应,准确地说,这将是错误处理,以及我需要的一些信息:示例 - { error: "ERROR_FROM_X_TO_Y" } (I '将需要错误属性)。
const postReq = () => {
return async () => {
try {
const url = '/exampleUrl/account-data';
try {
const response = await axios.post(url);
} catch (err) {
console.log(err);
}
} catch (error) {
console.log("error");
}
};
};
我已经尝试 console.log 响应,但它不起作用。
实际上错误存在于您的响应常量中,您是否尝试过:
await axios.post(url).catch((err) => { console.error(err) });
编辑:我在 github 上发现了这个问题,希望她能解决您的问题:
axios.post('/formulas/create', {
name: "",
parts: ""
}).then(response => {
console.log(response)
}).catch(error => {
console.log(error.response)
});
你能告诉我如何在 axios 中使用来自 post 类型请求的响应,它会给出错误 422(无法处理的实体)吗?我无法使用来自 API 的 JSON 响应,准确地说,这将是错误处理,以及我需要的一些信息:示例 - { error: "ERROR_FROM_X_TO_Y" } (I '将需要错误属性)。
const postReq = () => {
return async () => {
try {
const url = '/exampleUrl/account-data';
try {
const response = await axios.post(url);
} catch (err) {
console.log(err);
}
} catch (error) {
console.log("error");
}
};
};
我已经尝试 console.log 响应,但它不起作用。
实际上错误存在于您的响应常量中,您是否尝试过:
await axios.post(url).catch((err) => { console.error(err) });
编辑:我在 github 上发现了这个问题,希望她能解决您的问题:
axios.post('/formulas/create', {
name: "",
parts: ""
}).then(response => {
console.log(response)
}).catch(error => {
console.log(error.response)
});