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

How to handled error in onError ? #40

Closed
lyquocnam opened this issue Jul 26, 2018 · 3 comments
Closed

How to handled error in onError ? #40

lyquocnam opened this issue Jul 26, 2018 · 3 comments

Comments

@lyquocnam
Copy link

lyquocnam commented Jul 26, 2018

Dear author, i handled error in onError, so i don't want use try catch it again in my code. How to do that ?
i tried return null; in onError but not work.

 dynamic _onError(DioError e) {
    // handled..
   // ....
    return null; // <---
  }

currently i must do this to ignore exception, because it was handled as above:

try {
var response = await dio.post(....);
} catch (e) {}
@wendux
Copy link
Contributor

wendux commented Jul 31, 2018

A request must correspond to a response, even if it failed.
you can handle successful response by only suppling callback to then instead of using async...await to ignore exception:

dio.get(...).then((r)=>print(r))

@wendux wendux closed this as completed Sep 6, 2018
@jlcool
Copy link

jlcool commented Dec 23, 2018

@wendux 请求需要做单独的异常处理还必须得用await,不能用then。使用then,有异常catch不到,能不能不抛出异常而是返回一个异常状态,直接用then获取处理,比如这样
.then((response,error){ if(error!=null){ } })

@jlcool
Copy link

jlcool commented Dec 24, 2018

@wendux 请求需要做单独的异常处理还必须得用await,不能用then。使用then,有异常catch不到,能不能不抛出异常而是返回一个异常状态,直接用then获取处理,比如这样
.then((response,error){ if(error!=null){ } })

onError 返回Response 就可以

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

3 participants