Skip to main content

RestExcepction

The main exception class thrown by the Akatus SDK when API requests fail. Namespace: Akatus Inheritance: System.Exception

Properties

StatusCode
int
The HTTP status code returned by the API
StatusDesciption
string
The HTTP status description
Note: The property name contains a typo (“Desciption” instead of “Description”) in the SDK source code
ErrorMessages
List<string>
A list of error messages returned by the API. If the API returns XML error responses, the messages are parsed from the <descricao> tags. Otherwise, the raw error message is included.

Constructor

RestExcepction(string errorMessage, int statusCode, string statusDesciption)
Parameters:
  • errorMessage - The error message or XML response from the API
  • statusCode - The HTTP status code
  • statusDesciption - The HTTP status description

Error Handling Pattern

When making API calls with the Akatus SDK, wrap your code in a try-catch block to handle potential errors:
try
{
    // Create and configure cart
    Akatus.Carrinho.Carrinho carrinho = new Akatus.Carrinho.Carrinho();
    carrinho.Pagador.Nome = "NOME CLIENTE";
    carrinho.Pagador.Email = "email@cliente.com";
    
    // Process transaction
    Akatus.Carrinho.Retorno retorno = carrinho.processaTransacao();
}
catch (Akatus.RestExcepction ex)
{
    // Show HTTP status
    Response.Write(ex.StatusCode);
    Response.Write(ex.StatusDesciption);

    // Show error messages
    foreach (string error in ex.ErrorMessages)
    {
        Response.Write("<br />" + error);
    }
}
catch (Exception ex)
{
    // Handle other exceptions
    Response.Write(ex);
}

Common Scenarios

If your API key or token is invalid, you’ll receive a RestExcepction with a 401 or 403 status code. Check your configuration:
<appSettings>
  <add key="AkatusApiKey" value="YOUR-API-KEY"/>
  <add key="AkatusTokenNIP" value="YOUR-NIP-TOKEN"/>
</appSettings>
Missing or invalid transaction data will result in a RestExcepction with a 400 status code. The ErrorMessages list will contain specific validation failures.
Network connectivity issues may result in other exception types. Always include a general catch (Exception ex) block to handle unexpected errors.

Example: Logging Errors

try
{
    var consulta = new Akatus.ConsultaStatus.Consulta();
    var retorno = consulta.consultaStatusTransacao(transactionId);
}
catch (Akatus.RestExcepction ex)
{
    // Log detailed error information
    Logger.Error($"Akatus API Error: {ex.StatusCode} - {ex.StatusDesciption}");
    
    foreach (string error in ex.ErrorMessages)
    {
        Logger.Error($"  - {error}");
    }
    
    // Show user-friendly message
    ShowError("Unable to process transaction. Please try again.");
}

Build docs developers (and LLMs) love