DepositError instance with a machine-readable code property. The error class is the same as the web SDK, but the mobile SDK has additional error codes for browser and deep link failures.
DepositError
import { DepositError, getDisplayMessage } from '@swype-org/deposit-mobile';
class DepositError extends Error {
readonly code: DepositMobileErrorCode;
constructor(code: DepositMobileErrorCode, message: string);
}
Error codes
Mobile-specific codes
| Code | Meaning | User-facing message |
|---|---|---|
DEPOSIT_DISMISSED | User dismissed the deposit flow before completing the payment. | ”The deposit was dismissed before the transfer completed.” |
BROWSER_FAILED | Failed to open the in-app browser (e.g. openUrl threw an error). | ”Unable to open the payment browser. Please try again.” |
BROWSER_DISMISSED | Deprecated alias for DEPOSIT_DISMISSED. | ”The deposit was dismissed before the transfer completed.” |
DEEP_LINK_INVALID | The callback deep link was malformed or missing required parameters. | ”The payment callback was malformed. Please try again.” |
Shared codes (same as web SDK)
| Code | Meaning | User-facing message |
|---|---|---|
SIGNER_REQUEST_FAILED | Signer returned a non-2xx response. | ”Unable to start the payment. Please try again.” |
SIGNER_NETWORK_ERROR | Network failure reaching the signer. | ”Unable to reach the payment server. Check your connection and try again.” |
SIGNER_RESPONSE_INVALID | Signer response missing required fields (merchantId, payload, signature, preview). | ”The payment server returned an unexpected response.” |
SIGNER_TIMEOUT | Signer did not respond within signerTimeoutMs. | ”The payment server took too long to respond. Please try again.” |
FLOW_TIMEOUT | Entire flow exceeded flowTimeoutMs. | ”The deposit flow timed out. Please try again.” |
INVALID_REQUEST | Bad input (missing amount, invalid address, destroyed instance, etc.). | ”Invalid payment request. Please check your input.” |
getDisplayMessage
Returns a user-friendly display string for aDepositError. You can show this directly in your UI.
function getDisplayMessage(error: DepositError): string
Usage
import { DepositError, getDisplayMessage } from '@swype-org/deposit-mobile';
try {
await deposit.requestDeposit({ /* ... */ });
} catch (err) {
if (err instanceof DepositError) {
Alert.alert('Payment Error', getDisplayMessage(err));
console.error(err.code, err.message);
}
}
Handling specific error codes
try {
await deposit.requestDeposit({ /* ... */ });
} catch (err) {
if (!(err instanceof DepositError)) throw err;
switch (err.code) {
case 'DEPOSIT_DISMISSED':
// User intentionally closed, no action needed
break;
case 'BROWSER_DISMISSED':
// Deprecated alias for DEPOSIT_DISMISSED
break;
case 'BROWSER_FAILED':
// Could not open browser, prompt retry or show fallback
showRetryDialog(getDisplayMessage(err));
break;
case 'DEEP_LINK_INVALID':
// Malformed callback, log for investigation
reportError(err);
break;
case 'SIGNER_REQUEST_FAILED':
case 'SIGNER_NETWORK_ERROR':
case 'SIGNER_TIMEOUT':
// Signer issue, prompt retry
showRetryDialog(getDisplayMessage(err));
break;
case 'SIGNER_RESPONSE_INVALID':
// Integration bug, log for investigation
reportError(err);
break;
case 'FLOW_TIMEOUT':
showRetryDialog(getDisplayMessage(err));
break;
case 'INVALID_REQUEST':
showValidationError(getDisplayMessage(err));
break;
}
}
DepositMobileErrorCode
The union of all mobile error code strings:type DepositMobileErrorCode =
| 'DEPOSIT_DISMISSED'
| 'BROWSER_FAILED'
/** @deprecated Use 'DEPOSIT_DISMISSED' instead. */
| 'BROWSER_DISMISSED'
| 'DEEP_LINK_INVALID'
| 'SIGNER_REQUEST_FAILED'
| 'SIGNER_NETWORK_ERROR'
| 'SIGNER_RESPONSE_INVALID'
| 'SIGNER_TIMEOUT'
| 'FLOW_TIMEOUT'
| 'INVALID_REQUEST';