jjzjj

validateStatus

全部标签

javascript - 我可以根据响应状态在 axios post 中抛出错误吗

是否有可能在axios中的.then()block内故意抛出错误?例如,如果api以204状态代码响应,我可以抛出错误并运行catchblock吗?例如:axios.post('link-to-my-post-service',{json-input}).then(response=>{if(response.status===200){//proceed...}else{//throwerrorandgotocatchblock}}).catch(error=>{//runthiscodealwayswhenstatus!==200});编辑我试过了,但是没用:varinstance