swarm-ui: let a closed stream reconnect and a failed caps read retry
When the server answers an event stream with an error status the browser gives up and the badge stayed on disconnected with nothing to press. The terminal, its state header and the messages page now offer a reconnect, and the one rule for the state after an error moved into a tested helper. The resource caps panel gets a retry beside its error, and its loading state announces itself.
This commit is contained in:
parent
9b1fe85706
commit
31b7452e56
1 changed files with 118 additions and 34 deletions
14
frontend/packages/swarm-ui/src/ui/stream/connection.ts
Normal file
14
frontend/packages/swarm-ui/src/ui/stream/connection.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// The state of an `EventSource` as the swarm UI's stream hooks report it.
|
||||
|
||||
export type ConnectionState = "connecting" | "open" | "reconnecting" | "closed";
|
||||
|
||||
/** `EventSource.CONNECTING`: the browser is retrying by itself. */
|
||||
const CONNECTING = 0;
|
||||
|
||||
/** The state after an `error` event. While the browser is still retrying
|
||||
* (`readyState` 0), the stream is "reconnecting". Any other state means the
|
||||
* browser gave up, which it does when the server answers with a non-200 status
|
||||
* or a wrong content type, so nothing reopens the stream unless the page does. */
|
||||
export function connectionAfterError(readyState: number): ConnectionState {
|
||||
return readyState === CONNECTING ? "reconnecting" : "closed";
|
||||
}
|
||||
Loading…
Reference in a new issue