Le tre classi
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
# availableramificando su un fallimento
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)
raiseNunca coincider sul messaggio
Situat e codis sono stabili. Il messaggio è prosa: è escrito per una persona, può ser reescrit, e è tradut in places. Una condizion construida sobre ella romperà quietosamente.
i dettagli portano ciò che tu necessari per decide
Alcuni renegatis non sono tanto fallimenti quanto una question. Quando un renegatis ha strutturat i dati dietro di esso, esso arriva in details, per cui votre interface puès offrire la scelta real in lugar di mostrare un betch.
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)Codis que vedrà presto
| codi | status | Significado |
|---|---|---|
| non autorizzato | 401 | La sessione non è valida. Già rejuzgat una volta prima de vedîla. |
| not_enough_credits | 402 | Carrerere necessari e disponibili. |
| Tempo de cessio | 408 | Non risponde entro il termine. |
| Inaccessibile | 503 | La richiesta non arrivava mai. |
| storage_not_local | 400 | Que l'archivament non ha files a lere — use run(). |
| storage_is_local | 400 | Un computer mantiene i suoi files sul machinò; ningune e caricat. |
| context_too_large | 400 | Refusa prima di caricar nulla. |
| neocone | varia | La risposta non portava codigo. |
Cada pagina di referenza lista i cods che il suo proprio appello può elevare.