Skip to content

Commit

Permalink
Add HTTP response code to ErrorEvent (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
vyndor authored Oct 12, 2023
1 parent 9b227cf commit d504e2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
super.onFailure(webSocket, t, response);
try {
Client.this.executor.submit(() -> {
Client.this.handleConnectionError(t);
Integer responseCode = (response != null) ? response.code() : null;
listener.onError(Client.this, new ErrorEvent(t, responseCode));
Client.this.processDisconnect(CONNECTING_TRANSPORT_CLOSED, "transport closed", true);
if (Client.this.getState() == ClientState.CONNECTING) {
// We need to schedule reconnect from here, since onClosed won't be called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

public class ErrorEvent {
private final Throwable error;
private final Integer httpResponseCode;

ErrorEvent(Throwable t) {
this(t, null);
}

ErrorEvent(Throwable t, Integer httpResponseCode) {
this.error = t;
this.httpResponseCode = httpResponseCode;
}

public Throwable getError() {
return error;
}

/**
* @return http response code or null if not an http error
*/
public Integer getHttpResponseCode() {
return httpResponseCode;
}
}

0 comments on commit d504e2f

Please sign in to comment.