Skip to main content

Overview

Proper error handling is crucial for building robust applications with Transaction API. This guide covers common error scenarios, best practices, and implementation patterns.

Error Response Format

All API errors follow a consistent format:

Common Error Scenarios

Authentication Errors

Invalid Token

Status: 401 Code: UNAUTHORISED

Invalid Credentials

Status: 401 Code: INVALID_CREDENTIALS

Validation Errors

Invalid Input

Status: 400 Code: VALIDATION_INVALID

Duplicate Entry

Status: 400 Code: DUPLICATE_ENTRY

Resource Errors

Not Found

Status: 404 Code: NOT_FOUND

Insufficient Balance

Status: 400 Code: INSUFFICIENT_BALANCE

Error Handling Patterns

Basic Error Handling

Advanced Error Handling

Retry Logic

Exponential Backoff

Circuit Breaker Pattern

User-Friendly Error Messages

Error Message Mapping

Error Display Components

Logging and Monitoring

Error Logging

Error Metrics

Testing Error Scenarios

Unit Tests

Integration Tests

Best Practices

1

Handle All Error Types

Implement specific handling for different error codes and scenarios.
2

Provide User Feedback

Show clear, actionable error messages to users.
3

Implement Retry Logic

Use exponential backoff for transient errors.
4

Log and Monitor

Track errors for debugging and system health monitoring.
5

Test Error Scenarios

Write tests for common error conditions.

Common Pitfalls

Problem: Treating all errors the same waySolution: Implement specific handling for different error codes
Problem: Giving up on temporary failuresSolution: Implement retry logic with exponential backoff
Problem: Showing raw error messages to usersSolution: Map error codes to user-friendly messages
Problem: Difficult to debug production issuesSolution: Implement comprehensive error logging