HttpError

tcmts.server.HttpError · #tvc5kibj · class

A failure meant for the caller: its status and message reach the browser (other errors are hidden in production). It runs anywhere, so browser code can tell one apart (error.name === "HttpError", error.status).

export class HttpError extends Error {
  readonly status: number;
  /** seconds, sent as Retry-After (429s from rateLimit set it) */
  readonly retryAfter?: number;
  constructor(status: number, message: string, opts: { retryAfter?: number } = {}) {
    super(message);
    this.name = "HttpError";
    this.status = status;
    if (opts.retryAfter !== undefined) this.retryAfter = opts.retryAfter;
    // what tcm's runtime knows a deliberate error by, whichever copy of this class made it
    (this as unknown as Record<symbol, boolean>)[Symbol.for("tcm.httpError")] = true;
  }
}

used by