Ignore http 503 error from socket server

This commit is contained in:
Luck 2022-02-09 19:59:01 +00:00
parent bc15e348f5
commit 0fe85ed6ff
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -98,15 +98,24 @@ public class WebEditorSession {
this.socket = socket; this.socket = socket;
this.plugin.getWebEditorStore().sockets().putSocket(this.sender, this.socket); this.plugin.getWebEditorStore().sockets().putSocket(this.sender, this.socket);
} catch (Exception e) { } catch (Exception e) {
if (e instanceof UnsuccessfulRequestException && ((UnsuccessfulRequestException) e).getResponse().code() == 502) { if (!ignoreSocketConnectError(e)) {
// 502 - bad gateway, probably means the socket service is offline
// that's ok, no need to send a warning
return;
}
this.plugin.getLogger().warn("Unable to establish socket connection", e); this.plugin.getLogger().warn("Unable to establish socket connection", e);
} }
} }
}
private static boolean ignoreSocketConnectError(Exception e) {
if (e instanceof UnsuccessfulRequestException) {
UnsuccessfulRequestException req = (UnsuccessfulRequestException) e;
int code = req.getResponse().code();
// 502 - bad gateway / 503 - service unavailable
// probably means the socket service is offline, that's ok, no need to send a warning
return code == 502 || code == 503;
}
return false;
}
private void createInitialSession() { private void createInitialSession() {
Objects.requireNonNull(this.initialRequest); Objects.requireNonNull(this.initialRequest);