/** What each HTTP failure looks like to a person. Lines in `command` read like git's own output. */ export type ErrorKind = | "unauthorized" | "forbidden" | "not-found" | "rate-limited" | "client" | "server" | "unavailable"; export type ErrorCopy = { title: string; description: string; command: string }; export const ERROR_COPY: Record = { unauthorized: { title: "Sign in to keep going.", description: "This page needs an account. Sign in, or create one — it only takes a moment.", command: "fatal: Authentication required", }, forbidden: { title: "This one's behind a locked door.", description: "You're signed in, but you don't have access here. Ask an owner of the repository or organization to add you.", command: "remote: Permission denied", }, "not-found": { title: "This branch doesn't lead anywhere.", description: "The page may have moved or been deleted — or it's private and you don't have access to it.", command: "fatal: couldn't find remote ref", }, "rate-limited": { title: "Easy there.", description: "You've made a lot of requests in a short time. Wait a moment, then try again.", command: "remote: rate limit exceeded", }, client: { title: "That request didn't go through.", description: "Something about it wasn't quite right. Go back and try again.", command: "error: request rejected", }, server: { title: "We hit a snag on our end.", description: "It's not you. Give it a moment and try again.", command: "error: failed to push some refs", }, unavailable: { title: "Back in a moment.", description: "gitfor is briefly unavailable — usually for a quick update. Try again shortly.", command: "remote: service unavailable", }, }; const UNAUTHORIZED = 401; const FORBIDDEN = 403; const NOT_FOUND = 404; const TOO_MANY = 429; const SERVER_MIN = 500; const UNAVAILABLE = 503; export function errorKind(status: number): ErrorKind { if (status === UNAUTHORIZED) return "unauthorized"; if (status === FORBIDDEN) return "forbidden"; if (status === NOT_FOUND) return "not-found"; if (status === TOO_MANY) return "rate-limited"; if (status === UNAVAILABLE) return "unavailable"; return status >= SERVER_MIN ? "server" : "client"; }