Die drei Klassen
import { IaGenifyError, Unauthorized, NotEnoughCredits } from "iagenify";
class IaGenifyError extends Error {
status; // HTTP status
code; // short, stable identifier
details; // present when the refusal carries structured data
}
class Unauthorized extends IaGenifyError {} // 401, code "unauthorized"
class NotEnoughCredits extends IaGenifyError { // 402, code "not_enough_credits"
required;
available;
}from iagenify import IaGenifyError, Unauthorized, NotEnoughCredits
# class IaGenifyError(Exception):
# status # HTTP status
# code # short, stable identifier
# details # present when the refusal carries structured data
#
# class Unauthorized(IaGenifyError): ... # 401, code "unauthorized"
# class NotEnoughCredits(IaGenifyError): # 402, code "not_enough_credits"
# required
# availableVerzweigung auf einen Ausfall
try {
await assistant.generate({ inputs });
} catch (err) {
if (err instanceof NotEnoughCredits) {
return topUp(err.required - err.available);
}
if (err instanceof Unauthorized) {
return reauthenticate();
}
if (err instanceof IaGenifyError) {
console.error(err.status, err.code, err.message);
throw err;
}
throw err; // not from the SDK
}try:
assistant.generate(inputs=inputs)
except NotEnoughCredits as error:
top_up(error.required - error.available)
except Unauthorized:
reauthenticate()
except IaGenifyError as error:
print(error.status, error.code, error)
raiseStatus und Code sind stabil. Die Nachricht ist Prosa: es ist für eine Person geschrieben, es kann neu geschrieben werden, und es wird in Orten übersetzt. Eine Bedingung darauf gebaut wird ruhig brechen.
Details trägt, was Sie zu entscheiden brauchen
Einige Ablehnungen sind nicht Fehler, sondern eine Frage. Wenn eine Ablehnung Daten dahinter strukturiert hat, kommt sie auf details, so dass Ihre Schnittstelle die richtige Wahl bieten kann, anstatt eine Sackgasse anzuzeigen.
try {
await domain.mail.enable();
} catch (err) {
if (err.code === "mail_would_replace_mx") {
// err.details.current — where mail goes today
// err.details.hint — the suggested way out
return offerChoice(err.details);
}
throw err;
}try:
domain.mail.enable()
except IaGenifyError as error:
if error.code != "mail_would_replace_mx":
raise
# error.details["current"] — where mail goes today
# error.details["hint"] — the suggested way out
offer_choice(error.details)Codes, die Sie früh treffen werden
| Code | Status | Bedeutung |
|---|---|---|
| Unbefugt | 401 | Die Sitzung ist nicht gültig. Sie wurde bereits einmal ausprobiert, bevor Sie sie sahen. |
| not_enough_credits | 402 | Beförderungen erforderlich und verfügbar. |
| Zeitlimit | 408 | Keine Antwort innerhalb der Frist. |
| nicht erreichbar | 503 | Die Anfrage kam nie an. |
| storage_not_local | 400 | Dieser Speicher hat keine Dateien zu lesen — verwenden Sie Run(). |
| storage_is_local | 400 | Ein Computer hält seine Dateien auf dem Rechner; nichts wird hochgeladen. |
| context_too_large | 400 | Zurückgenommen, bevor etwas angeklagt wurde. |
| unbekannt | variiert | Die Antwort trug keinen Code. Lesen Sie den Status. |
Jede Referenzseite listet die Codes auf, die ihr eigener Aufruf erhöhen kann.