Conceitos

Erros

Tre classi, exportate tal instuzion de opere. Ogni fallimento porta un status e un codice corto — questi sono i due campi a rami.

IaGenifyErrorUnauthorizedNotEnoughCredits
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

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
#     available

ramificando 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)
    raise
Nunca 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

codistatusSignificado
non autorizzato401La sessione non è valida. Già rejuzgat una volta prima de vedîla.
not_enough_credits402Carrerere necessari e disponibili.
Tempo de cessio408Non risponde entro il termine.
Inaccessibile503La richiesta non arrivava mai.
storage_not_local400Que l'archivament non ha files a lere — use run().
storage_is_local400Un computer mantiene i suoi files sul machinò; ningune e caricat.
context_too_large400Refusa prima di caricar nulla.
neoconevariaLa risposta non portava codigo.

Cada pagina di referenza lista i cods che il suo proprio appello può elevare.