Skip to content

Commit

Permalink
Add explicit error message if e.getMessage is null
Browse files Browse the repository at this point in the history
Summary:
In the NetworkingModule, if the http request failed, we send a `didCompleteNetworkResponse` event with the error message, which is used on JS side to determine if the request was erroring. Currently we get the error message from `e.getMessage()`, however, not all exceptions have a message and it might therefore return null and thus resulting in no error on JS side. This change checks if the message is null and if so uses a default message.

In android send a request using XMLHttpRequest with a timeout set to a server that has a delay larger than the timeout (so we force the timeout to happen).

```
const request =  new XMLHttpRequest();
request.open('GET', "http://localhost:3000/", true);
request.timeout = 1000;
request.ontimeout = () => { console.log('ontimeout'); };
request.send();
```

See the timeout callback being called correctly.

Fixes facebook#11666
Closes facebook#13407

Differential Revision: D4963764

Pulled By: hramos

fbshipit-source-id: 61ffcef9e0594fe9bface24fdb8bde1e6eec3990
  • Loading branch information
reneweb authored and thotegowda committed May 7, 2017
1 parent d50bdbc commit 0f38a01
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ public void onFailure(Call call, IOException e) {
return;
}
removeRequest(requestId);
ResponseUtil.onRequestError(eventEmitter, requestId, e.getMessage(), e);
String errorMessage = e.getMessage() != null
? e.getMessage()
: "Error while executing request: " + e.getClass().getSimpleName();
ResponseUtil.onRequestError(eventEmitter, requestId, errorMessage, e);
}

@Override
Expand Down

0 comments on commit 0f38a01

Please sign in to comment.