Pular para o conteúdo principal

Errors

HTTP status codes​

Amplia's API answers with an HTTP status code:

StatusMeaning
200 OKThe request was processed; the body depends on the operation.
400 Bad RequestSyntax error, for instance a required field is missing.
401 UnauthorizedThe API key was not sent or is invalid.
403 ForbiddenThe API key is valid, but the application lacks the permission for the operation.
422 Unprocessable EntityAPI error, for instance an entity id that is not found; the body is an ErrorModel.
500 Internal Server ErrorUnexpected error; the exceptionCode in the body helps Lacuna support diagnose it.

The error body​

An ErrorModel has a code, a message and details. The messages don't follow the Accept-Language header: log them rather than show them to users. The e-CPF demo shows users the error code, never the message, and treats Amplia's 4xx answers as refusals and anything else as a failure.

What the client libraries throw​

ClientAPI error (422)Other HTTP errorsEndpoint unreachable
Node.jsAmpliaError, whose code is the error code; OrderLocketError when the code is OrderLockedRestError, whose code is the HTTP statusRestUnreachableError
JavaRestErrorException, with the status and the message but not the error codeRestErrorException, or RestResourceNotFoundException for some 404 responsesRestUnreachableException
PHPAmpliaException (getErrorCode(), getErrorMessage()); OrderLockedException when the code is OrderLockedRestErrorException (getStatusCode())RestUnreachableException
PythonRestError, with only the HTTP status (see below)RestErrorRestUnreachableError
.NETAmpliaException (Code, CodeStr, ErrorMessage); OrderLockedException when the code is OrderLockedRestException from Lacuna.RestClient

The Python client 1.0.0 defines AmpliaError and OrderLockedError for 422 responses, but its error handling reads the code from the wrong object, so every error response comes out as RestError with only the HTTP status.

Error codes​

The API's ErrorCodes enum, which the .NET client exposes as AmpliaException.Code, has 160 codes in Amplia 5.0.1; the Node.js and PHP clients list 95 of them (AmpliaErrorCodes in Node.js, ErrorCodes in PHP). These are the ones that the calls in this guide return, with what Amplia 5.0.1 means by each:

AreaCodeMeaning
OrdersOrderNotFoundNo order with that id (or, on the issue page, with that secret).
OrderDeletedThe order was deleted.
OrderAlreadyFulfilledThe order's certificate was already issued: it can't be issued again, deleted, or have its link sent.
OrderLockedThe order is locked.
CARequiredNo caId was sent and the application has no default CA.
CANotFound, TemplateNotFoundNo CA, or no template, with that id.
CANotActiveThe CA isn't active, so it can't issue.
NoSuitableTemplateFoundThe subscription has no template for the order's format.
ValidityRequired, KindRequiredAn order without a template needs validityEnd and kind; an order on a template with no default validity needs validityEnd.
ValidityStartRequired, BadValidityStartAn order with issuePendingApproval needs a validityStart in the future.
TemplateForbidsCustomValidity, TemplateForbidsParameterThe template doesn't let the order set its validity, or that parameter.
CertificateKindNotSupportedThe kind (public-key or attribute) doesn't match what the CA or the template issues.
BadOrderParametersA parameter is missing or not allowed by the template.
InvalidCpf, InvalidCnpj, InvalidPhoneNumberThe CPF, CNPJ or phone number is not valid.
DnsNamesRequired, BadDnsNameAn SSL/TLS order has no DNS name, or one that is not valid.
IssuanceCsrRequiredA public-key certificate needs a CSR (or a key held by Amplia).
CsrNotExpectedAn attribute certificate takes no CSR or key.
BadCsrThe CSR is not valid.
KeySizeNotSupported, BadKeySizeThe key size is not valid, or is below the template's minimum.
DigestAlgorithmNotSupportedThe digest algorithm is not supported.
Issue linkNoEmailAddress, EmailDisabledThe order has no email address, or the instance can't send email.
NoPhoneNumber, SmsDisabledThe order has no phone number, or the instance can't send SMS.
IssueSessionExpired, NoMoreConfirmAttemptsRemainingDuring issuance on Amplia's issue page: the session expired, or the holder used up the attempts to type the code sent by SMS.
CertificatesCertificateNotFoundNo certificate with that id.
CertificateAlreadyRevokedThe certificate was already revoked.

A permission the application lacks is answered with 403 Forbidden, not with an error code: in Amplia 5.0.1, no call returns the AccessDeniedTo… codes that the clients list.

The SSL/TLS demo maps BadDnsName and BadCsr to messages of its own.

See also​

View as Markdown