Files
CertScope-Public/lib/inspect/http-status.ts
T

18 lines
826 B
TypeScript

export type HttpStatusTone = "green" | "amber" | "red" | "muted";
export type HttpStatusSemantics = {
label: "Incomplete" | "Informational response" | "Healthy response" | "Redirect response" | "Client error" | "Server error";
tone: HttpStatusTone;
};
export function statusForHttp(status: unknown): HttpStatusSemantics {
if (typeof status !== "number" || !Number.isInteger(status) || status < 100 || status > 599) {
return { label: "Incomplete", tone: "muted" };
}
if (status < 200) return { label: "Informational response", tone: "muted" };
if (status < 300) return { label: "Healthy response", tone: "green" };
if (status < 400) return { label: "Redirect response", tone: "muted" };
if (status < 500) return { label: "Client error", tone: "amber" };
return { label: "Server error", tone: "red" };
}