The PayMittoError 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.
PayMitto.types.ts
export interface PayMittoError {
code: string;
message: string;
}
Property Type Required Description code stringYes A unique error code that identifies the type of error. Use consistent codes for easier debugging and error handling. message stringYes A human-readable description of the error that occurred. This message may be displayed to the user or logged for debugging.
Code Description 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
App.tsx
import type {
PayMittoTokenResponse,
PayMittoError
} from 'react-native-paymitto-sdk';
const fetchAccessTokenDetails = async (): Promise<PayMittoTokenResponse | PayMittoError> => {
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',
};
}
};
App.tsx
import type {
PayMittoTransferRequest,
PayMittoTransferResponse,
PayMittoError
} from 'react-native-paymitto-sdk';
const verifyFundsAndCreateTransfer = async (
request: PayMittoTransferRequest
): Promise<PayMittoTransferResponse | PayMittoError> => {
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',
};
}
};
JSON
{
"code": "INSUFFICIENT_FUNDS",
"message": "The source account does not have sufficient funds for this transfer"
}