Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题 | question] errorThrower 没有作用 #10187

Closed
choi2k opened this issue Aug 31, 2022 · 1 comment
Closed

🧐[问题 | question] errorThrower 没有作用 #10187

choi2k opened this issue Aug 31, 2022 · 1 comment

Comments

@choi2k
Copy link

choi2k commented Aug 31, 2022

🧐 问题描述 | Problem description

https://umijs.org/docs/max/request
“其中 errorThrower 接收你后端返回的数据并且需要抛出一个你自己设定的 error, 你可以在这里根据后端的数据进行一定的处理。”

测试后端返回错误的时候, 使用 errorThrower 来做初步处理. 然后 errorHandler 再后续处理.

预期:
应该回进到 errorThrower 然后 errorHandler.
实际:
测试只会进到 errorHandler.

测试所用的最新版本的 ant-design pro, 由 ”pro create myapp“ 创建.

💻 示例代码 | Sample code

// app.tsx
 
export const request: RequestConfig = {
  timeout: 1000,
  // other axios options you want
  errorConfig: {
    errorHandler() {
      console.info('errorHandler');
    },
    errorThrower() {
      console.info('errorThrower');
    },
  },
  requestInterceptors: [
    (url, options) => {
      console.info('requestInterceptors');
      return { url, options };
    },
  ],
  responseInterceptors: [
    (response) => {
      console.info('responseInterceptors');
      return response;
    },
  ],
};
// api 返回 500 错误
request<API.LoginResult>('/api/500', {
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });

🚑 其他信息 | Other information

Screenshot 2022-08-31 at 1 55 34 PM

实际只有 requestInterceptors 和 errorHandler 有跑

OS: Mac 12.4

Node:v16.15.1

浏览器 | browser:Chrome

@chenshuai2144
Copy link
Collaborator

chenshuai2144 commented Sep 24, 2022

500 和 404 这些http错误不会进入 errorThrower 的,可以看看源码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants