File size: 1,532 Bytes
51c026d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import type { RemoteServiceErrorCode } from "@earendil-works/chord";
type ServerOperationErrorCode =
| RemoteServiceErrorCode
| "wrong_server"
| "session_not_found"
| "session_ambiguous"
| "session_not_attached"
| "server_draining";
export const INTERNAL_SERVER_ERROR_MESSAGE = "Internal server error";
/** A host or lifecycle error that can safely cross the protocol boundary. */
export class ServerError extends Error {
readonly code: ServerOperationErrorCode;
constructor(code: ServerOperationErrorCode, message: string) {
super(message);
this.name = "ServerError";
this.code = code;
}
}
export class WrongServerError extends ServerError {
constructor() {
super("wrong_server", "Request was addressed to another server");
this.name = "WrongServerError";
}
}
export class SessionNotFoundError extends ServerError {
constructor(message = "Session was not found") {
super("session_not_found", message);
this.name = "SessionNotFoundError";
}
}
export class SessionAmbiguousError extends ServerError {
constructor() {
super("session_ambiguous", "Session ID matches more than one session");
this.name = "SessionAmbiguousError";
}
}
export class SessionNotAttachedError extends ServerError {
constructor() {
super("session_not_attached", "Session is not attached to this client");
this.name = "SessionNotAttachedError";
}
}
export class ServerDrainingError extends ServerError {
constructor() {
super("server_draining", "Server is draining");
this.name = "ServerDrainingError";
}
}
|