为什么 axios 在 catch 以后依然还在执行上面的逻辑?-灵析社区

爬虫爬呀爬

我想问为什么接口在 `500` 之后依然会进行跳转呢?难道不是 `catch` 然后弹窗报错了么? const Api_Common = async (Path: string, Function: string, Params: any = {}) => await axios .post(`host`, Params) .then((data: Response) => data.data.Response) .catch((e) => { return ErrorState.dispatch(Publish(e.response.data.Error)) }) const Api_Account_Register = (mobile: string, password: string, captcha: string) => Api_Common( Path, "account_register", { mobile: mobile, password: password, captcha: captcha }) Api_Account_Register( mobile, password, code ) .then(() => messageApi.success('注册成功').then(() => navigate('/首页')))

阅读量:13

点赞量:0

问AI
"Api_Common"确实"catch"了,但是"catch"没有继续把错误抛出,"catch"返回了一个新的"promise",也就继续执行"Api_Account_Register"后面的"then"了 "MDN -Promise.catch" (https://link.segmentfault.com/?enc=rNmUm1WGPoKXzLGimwurgA%3D%3D.iS3onXQVELyl3QGLbUMFb%2BK0GOUzKrusqF55bGBVOQslKXZlk6wNhj5eRxVlwPN%2FgcHzocU7UO7G4g11cZHX67%2F4MLJmRKGwceElSSbKknxLD1VVbk5xV1ZxEZmAoF2AuLgF20bqpQ%2BUIEX1Aus1KitTjwp%2FvVrWTk%2FkFm%2BR%2B6VnfyawyLMSuUonTS34dHEF)