I am trying to override the default behavior of connection lost by implement IConnectionLost. After some digging, I realized that the IConnectionLost only deals with connection error. Is there a way to catch a http error such as 5xx?
Hi @louis-she, I can’t think of a way to do it with the IConnectionLost
token, which, as you say, only responds to network errors, or 503 errors in a JupyterHub context (e.g. here).
You could try polling requests yourself using the ServiceManager
and listening for other error codes. It would involve a bit of extra network traffic, but may not be a big deal for your use case.
1 Like
I come up with a dirty workaround that override the fetch
methods.
const originalFetch = ServerConnection.defaultSettings.fetch
ServerConnection.defaultSettings.fetch = (input: RequestInfo, init?: RequestInit) => {
return originalFetch(input, init).then(response => {
if (response.status > 500) {
// Handle 5xx error
}
return response
})
}
Don’t know the side effect but yet it works fine for me.