Overview
The PayNow SDK provides built-in error handling utilities to help you distinguish between PayNow API errors and other types of failures. All API errors follow a consistent structure defined by the PayNow API specification.PayNowError Type
The SDK exports a specializedPayNowError type that represents errors returned by the PayNow API:
AxiosError with PayNow-specific error schema information and guarantees that a response property exists.
Error Structure
PayNow API errors have the following structure:Type Guard: isPayNowError
The SDK provides a type guard function to safely check if an error is a PayNow API error:Implementation
- The error is an Axios error
- A response exists (not a network/timeout error)
- The response data is an object
- The object contains
status,code, andmessagefields
Basic Error Handling
Here’s how to handle errors in your application:Error Handling Patterns
Non-PayNow Errors
Not all errors are PayNow API errors. You may encounter:Network Errors
Timeout Errors
Request Cancellation
Error Response Structure
WhenisPayNowError returns true, you can safely access:
Best Practices
Always use the type guard
Always use the type guard
Always use
isPayNowError() before accessing error properties. This provides type safety and prevents runtime errors:Handle non-PayNow errors
Handle non-PayNow errors
Don’t assume all errors are PayNow errors. Network issues, timeouts, and other failures can occur:
Log errors for debugging
Log errors for debugging
Include relevant error information when logging:
Provide user-friendly messages
Provide user-friendly messages
Don’t expose raw API error messages to end users. Map error codes to user-friendly messages:
Next Steps
Authentication
Understand how authentication works in the SDK
Client Architecture
Learn about the client structure and type safety