failureOffunctionfunction failureOf(status: number, headers: Readonly<Record<string, string>>, body: Uint8Array<ArrayBufferLike>): FailureThe failure of an answer: the status, the code and the message of its error object, as far as it has them.
What Microsoft Graph says when it does not do what it was asked, and what a store makes of it: a failure is a status and an error object ({ "error": { "code", "message" } }); its kind is one of a closed list, decided by the code where there is one and by the status where there is not; and every kind is a problem of AnyFS by a total table written here, which the compiler holds. A condition that failed is a conflict only where the caller can say what the object is at; a throttle or a fault of the service is a problem worth a retry; a refusal of the token or of the account is not, and says which it was.
import { kindOf } from "./errors.ts";
kindOf({ status: 412, code: "preconditionFailed", message: "" }); // "precondition"
kindOf({ status: 429, code: "activityLimitReached", message: "" }); // "throttled"failureOffunctionfunction failureOf(status: number, headers: Readonly<Record<string, string>>, body: Uint8Array<ArrayBufferLike>): FailureThe failure of an answer: the status, the code and the message of its error object, as far as it has them.
FAILURE_KINDSconstconst FAILURE_KINDS: readonly ["not-found", "name-exists", "precondition", "locked", "throttled", "server", "denied", "bad-token", "too-large", "quota", "invalid", "redirect"]The kinds of failure: a closed list.
kindOffunctionfunction kindOf(f: Failure): "bad-token" | "denied" | "invalid" | "locked" | "name-exists" | "not-found" | "precondition" | "quota" | "redirect" | "server" | "throttled" | "too-large"The kind of a failure: its code where there is one, else its status.
problemOffunctionfunction problemOf(f: Failure, subject: Subject): ProblemThe problem a failure is. Missing and conflict are made by the caller, which knows what it asked; here they are the problems a caller that does not know gets.
Failuretypeno test imports ittype Failure = { readonly status: number; readonly code: string; readonly message: string; readonly retryAfterMs?: number };What the service answered when it failed.
FailureKindtypeno test imports ittype FailureKind = (typeof FAILURE_KINDS)[number];One kind of failure.