Skip to main content

Error Handling

Each method call in the ChargeOver Java wrapper (such as create, update, findById) can fail due to various reasons, such as invalid data, network issues, or authentication errors. The library provides a getLastError() method that can retrieve the latest error encountered during an operation.

Using getLastError() for Error Handling

After any operation, you can call getLastError() to check if an error occurred and retrieve a descriptive error message.

HashMap<String, String> customerData = new HashMap<>();
customerData.put("email", "newcustomer@example.com");
customerData.put("company", "New Company LLC");

int customerId = co.create(ChargeOver.Target.CUSTOMER, customerData);
if (customerId < 0) {
// Retrieve and print the error message
System.out.println("Error creating customer: " + co.getLastError());
} else {
System.out.println("Created Customer ID: " + customerId);
}

Types of Common Errors

Some common error types you might encounter include:

  • Invalid Authentication: Occurs if API credentials are incorrect.
  • Missing or Invalid Data: Triggered when required fields are not provided or have invalid formats.
  • Network Errors: Occur due to connectivity issues or server timeouts.

For more details on specific errors and potential error codes, refer to the API documentation and review how to handle and interpret errors based on the HTTP status codes or message strings.