Coder Social home page Coder Social logo

Comments (5)

OccurSomething avatar OccurSomething commented on June 15, 2024

拦截器里的Promise.reject(new Error("heheheeh",99))是故意的,另外Error构造方法不能放statuscode吗?

from fly.

wendux avatar wendux commented on June 15, 2024

我在本地测了一下你的case, 没有遇到过不走拦截器的情况,你可以先更新一下flyio到最新版试试。还有error对象你完全可以自定义,如:

  fly.interceptors.response.use(
      (response) => {
        //定义错误信息
        return Promise.reject({
           message:"xxxx",
           status:0
        })
      },
      (err) => {
        console.log('fly.interceptors: error message=' + JSON.stringify(err));
      }
 )

from fly.

tangniyuqi avatar tangniyuqi commented on June 15, 2024

image
怎么我捕获到的格式这么乱呢 造成不能后续处理

from fly.

wendux avatar wendux commented on June 15, 2024

@tangniyuqi Error打印出来是文本,实际上是一个对象。

from fly.

tangniyuqi avatar tangniyuqi commented on June 15, 2024

@wendux 他的结构是什么呢,只想要里面的核心内容“未登录222!”

fly自带error处理直接就能获取错误内容,就像下面这个:
fly.interceptors.response.use((response) => {
let data = response.data;
let statusCode = data.statusCode;

if (statusCode !== 401) {
return Promise.reject(new Error('未登录3333!'));

return Promise.reject(new Error({
  message: '未登录4444!',
  status: 1111
})); 

}
return response;
}, (error) => {
let status = error.status;

if (status === 0) {
return '网络连接异常!';
} else if (status === 1) {
return '网络连接超时!';
} else if (status === 401) {
return '未登录!';
} else {
if (error.response.data.message) {
return error.response.data.message;
} else {
return '网络错误!请稍后再试。';
}
}
});

自定义的错误就不能直接打印吗?

from fly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.