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

Synchronous Error Handling #1095

Closed
KyleDBoyd opened this Issue Sep 18, 2015 · 2 comments

Comments

3 participants
@KyleDBoyd

KyleDBoyd commented Sep 18, 2015

In retrofit, I'm able to handle a network error in the onFailure(Throwable t) method of the Callback. What if I was already on the correct thread and I wanted to handle a response/network error in a catch block?

Is this possible in Retrofit 1.9? What about 2.0?

@f2prateek

This comment has been minimized.

Show comment
Hide comment
@f2prateek

f2prateek Sep 19, 2015

Contributor

Synchronous execution in Retrofit 1would throw a RetrofitError (or whatever you've adapted with a custom ErrorHandler).

try {
  T foo = service.foo(...);
} catch (RetrofitError e) {
  // Either the network responded with a code < 200 or >= 300 or some other error occurred.
}

The same code in v2 would look like this:

try {
  Response<T> response = service.foo(...);
  if (!response.isSuccess()) {
    // Network responded with a code < 200 or >= 300.
  }
} catch (IOException e) {
  // Some other error occurred.
}
Contributor

f2prateek commented Sep 19, 2015

Synchronous execution in Retrofit 1would throw a RetrofitError (or whatever you've adapted with a custom ErrorHandler).

try {
  T foo = service.foo(...);
} catch (RetrofitError e) {
  // Either the network responded with a code < 200 or >= 300 or some other error occurred.
}

The same code in v2 would look like this:

try {
  Response<T> response = service.foo(...);
  if (!response.isSuccess()) {
    // Network responded with a code < 200 or >= 300.
  }
} catch (IOException e) {
  // Some other error occurred.
}
@JakeWharton

This comment has been minimized.

Show comment
Hide comment
@JakeWharton

JakeWharton Sep 23, 2015

Collaborator

The question is really vague. Synchronous methods throw exceptions both on v1 and v2. You can use ErrorHandler on v1 to customize the error thrown.

If you have follow-ups, please ask on StackOverflow with the 'retrofit' tag as GitHub issues aren't the greatest place for that discussion.

Collaborator

JakeWharton commented Sep 23, 2015

The question is really vague. Synchronous methods throw exceptions both on v1 and v2. You can use ErrorHandler on v1 to customize the error thrown.

If you have follow-ups, please ask on StackOverflow with the 'retrofit' tag as GitHub issues aren't the greatest place for that discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment