umi#router JavaScript Examples

The following examples show how to use umi#router. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: request.js    From react-drag with MIT License 6 votes vote down vote up
// respone interceptors
service.interceptors.response.use(
  response => {
    // 200 maybe has error
    const { data = {} } = response;
    if (data.code === 0) {
      return data;
    }
    return data;
  },
  err => {
    const { response = {} } = err;
    if (err.response) {
      if (err.response.status === 401) {
        // 返回 401 清除token信息并跳转到登录页面
        router.push({
          pathname: '/login',
        });
        notification.error({
          message: '请求错误',
          description: '用户没有权限(令牌、用户名、密码错误),请重新登陆',
        });
      }
    }
    return Promise.resolve(response.data);
  },
);
Example #2
Source File: request.js    From spring-boot-plus-admin-react with Apache License 2.0 6 votes vote down vote up
errorHandler = error => {
  const { response } = error;

  if (response && response.status) {
    const errorText = codeMessage[response.status] || response.statusText;
    const { status, url } = response;
    notification.error({
      message: `请求错误 ${status}: ${url}`,
      description: errorText,
    });
    if (response.status === 401) {
      localStorage.clear();
      router.push('/user/login')
    }
  } else if (!response) {
    notification.error({
      description: '您的网络发生异常,无法连接服务器',
      message: '网络异常',
    });
  }

  return response;
}