Skip to content

Commit

Permalink
expose NetworkErrorException when request fails due to networking
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed May 27, 2019
1 parent f6f9f57 commit bfbdc62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
11 changes: 11 additions & 0 deletions auth0/src/main/java/com/auth0/android/NetworkErrorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.auth0.android;

/**
* Exception that represents a failure caused when attempting to execute a network request
*/
public class NetworkErrorException extends Auth0Exception {

public NetworkErrorException(Throwable cause) {
super("Failed to execute the network request", cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.support.annotation.VisibleForTesting;

import com.auth0.android.Auth0Exception;
import com.auth0.android.NetworkErrorException;
import com.auth0.android.RequestBodyBuildException;
import com.auth0.android.authentication.ParameterBuilder;
import com.auth0.android.callback.BaseCallback;
Expand Down Expand Up @@ -147,8 +148,7 @@ protected U parseUnsuccessfulResponse(Response response) {

@Override
public void onFailure(Request request, IOException e) {
Auth0Exception exception = new Auth0Exception("Failed to execute request to " + url.toString(), e);
postOnFailure(errorBuilder.from("Request failed", exception));
postOnFailure(errorBuilder.from("Request failed", new NetworkErrorException(e)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.auth0.android.request.internal;

import com.auth0.android.Auth0Exception;
import com.auth0.android.NetworkErrorException;
import com.auth0.android.RequestBodyBuildException;
import com.auth0.android.request.ErrorBuilder;
import com.auth0.android.request.ParameterizableRequest;
Expand Down Expand Up @@ -98,7 +99,7 @@ public T execute() throws Auth0Exception {
try {
response = client.newCall(request).execute();
} catch (IOException e) {
throw new Auth0Exception("Failed to execute request to " + url, e);
throw getErrorBuilder().from("Request failed", new NetworkErrorException(e));
}

if (!response.isSuccessful()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


import com.auth0.android.Auth0Exception;
import com.auth0.android.NetworkErrorException;
import com.auth0.android.RequestBodyBuildException;
import com.auth0.android.authentication.ParameterBuilder;
import com.auth0.android.callback.BaseCallback;
Expand Down Expand Up @@ -178,9 +179,9 @@ public void shouldPostOnFailure() throws Exception {
}

@Test
public void shouldBuildException() throws Exception {
public void shouldBuildNetworkErrorException() throws Exception {
baseRequest.onFailure(null, mock(IOException.class));
verify(errorBuilder).from(eq("Request failed"), any(Auth0Exception.class));
verify(errorBuilder).from(eq("Request failed"), any(NetworkErrorException.class));
}

@Test
Expand Down

0 comments on commit bfbdc62

Please sign in to comment.