ReadyRemit Error

Error response structure for SDK operations

Overview

The ReadyRemitError interface defines the structure for error responses that can occur during SDK operations. This interface should be returned by your callbacks (fetchAccessTokenDetails or verifyFundsAndCreateTransfer) when an error occurs instead of a successful response.


Definition

export interface ReadyRemitError {
  code: string;
  message: string;
}

Properties

PropertyTypeRequiredDescription
codestringYesA unique error code that identifies the type of error. Use consistent codes for easier debugging and error handling.
messagestringYesA human-readable description of the error that occurred. This message may be displayed to the user or logged for debugging.

Common Error Codes

CodeDescription
AUTH_ERRORAuthentication failed or token could not be retrieved
NETWORK_ERRORNetwork request failed
INVALID_RESPONSEServer returned an unexpected response format
INSUFFICIENT_FUNDSUser does not have sufficient funds for the transfer
TRANSFER_FAILEDTransfer could not be processed
VALIDATION_ERRORRequest validation failed
SERVER_ERRORInternal server error occurred

Sample Usage

Authentication Error

import type { 
  ReadyRemitTokenResponse, 
  ReadyRemitError 
} from 'react-native-ready-remit-sdk';

const fetchAccessTokenDetails = async (): Promise<ReadyRemitTokenResponse | ReadyRemitError> => {
  try {
    const response = await fetch('https://your-api.com/oauth/token', {
      method: 'POST',
    });

    if (!response.ok) {
      return {
        code: 'AUTH_ERROR',
        message: `Authentication failed with status ${response.status}`,
      };
    }

    const data = await response.json();
    return {
      accessToken: data.access_token,
      expiresIn: data.expires_in,
      scope: data.scope,
      tokenType: data.token_type,
    };
  } catch (error) {
    return {
      code: 'NETWORK_ERROR',
      message: error instanceof Error ? error.message : 'Network request failed',
    };
  }
};

Transfer Error

import type { 
  ReadyRemitTransferRequest, 
  ReadyRemitTransferResponse, 
  ReadyRemitError 
} from 'react-native-ready-remit-sdk';

const verifyFundsAndCreateTransfer = async (
  request: ReadyRemitTransferRequest
): Promise<ReadyRemitTransferResponse | ReadyRemitError> => {
  try {
    const response = await fetch('https://your-api.com/transfers', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(request),
    });

    if (!response.ok) {
      const errorData = await response.json();
      return {
        code: errorData.code || 'TRANSFER_FAILED',
        message: errorData.message || 'Transfer could not be processed',
      };
    }

    const data = await response.json();
    return { transferId: data.id };
  } catch (error) {
    return {
      code: 'NETWORK_ERROR',
      message: error instanceof Error ? error.message : 'Network request failed',
    };
  }
};

Example Error Response

{
  "code": "INSUFFICIENT_FUNDS",
  "message": "The source account does not have sufficient funds for this transfer"
}

Related