/** * A refused save is one of these two classes. The saver tells them apart rather * than reading a message, because it reacts to each one differently. */ /** The server's copy of the document, sent with a refused save. */ export type ServerVersion = { revision: number; body: unknown; text: string; words: number; /** ISO time of the server's last write; null when the server did not say. */ savedAt: string | null; }; /** * The server holds newer words than the save was built on, and nothing was * written. Retrying cannot help: the server refuses the same save again, so the * writer has to choose. */ export class SaveConflict extends Error { readonly server: ServerVersion; constructor(server: ServerVersion) { super('This was saved somewhere else since you opened it.'); this.name = 'SaveConflict'; this.server = server; } } /** * - `network`: the request never reached the server. * - `server`: the server answered with an error. * - `auth`: the session ended. A sign-in in another tab can fix it. * - `gone`: the document no longer exists for this writer. Retrying will not help. */ export type FailureKind = 'network' | 'server' | 'auth' | 'gone'; export class SaveFailure extends Error { readonly kind: FailureKind; constructor(kind: FailureKind, message: string) { super(message); this.name = 'SaveFailure'; this.kind = kind; } }