search

Home  >  Q&A  >  body text

javascript - How does axios handle errors of the same type uniformly?

// interceptors
axios.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    // 处理统一的验证失效错误.
    return Promise.reject(error);
  });

// 页面中
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  }, function (err) {
    // 在此处处理特定业务错误: 
    console.log(err.msg)
    // 问题是: 当我在拦截器里处理了验证失效后, 它还是会执行到这里面
  })

My question is: After I handle the validation error in the interceptor, how do I prevent the separate business processing in the page from executing?

巴扎黑巴扎黑2827 days ago634

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:12:54

    Business logic should be in then(), right?
    err handles errors

    reply
    0
  • Cancelreply