diff --git a/README.md b/README.md index 7a67118..3a36697 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ http.rate_limited Too many requests. Wait a moment and try again. net.unreachable Couldn't reach the server. Check your connection and try again. internal.unknown Something went wrong. Try again. {"type":"ai.provider.out_of_credits","title":"Your provider account is out of credits. Add credits and try again.","status":402} +{"type":"internal.unknown","title":"Something went wrong. Try again.","status":422} config.missing A required setting is missing: API_KEY. ``` diff --git a/examples/try.mjs b/examples/try.mjs index 64e46fc..206b01c 100644 --- a/examples/try.mjs +++ b/examples/try.mjs @@ -24,6 +24,11 @@ console.log(JSON.stringify(body)); // An Error you can throw. Its .message is the code, so logs stay searchable. // The sentence comes from describe(). +// Starting from a raw failure, problemFor() classifies it and keeps the +// observed status — including when the matched code registers several. +const fromRaw = errors.problemFor({ status: 422 }); +console.log(JSON.stringify(fromRaw)); + const err = errors.create("config.missing", { field: "API_KEY" }); console.log(err.message); console.log(errors.describe(err.code, err.params));