Error Handling
Introduction
The SDK provides a unified approach to handling errors by returning a WalletError
object as a response
whenever an error is returned by the Paysafe Wallet API.
Usage
- TypeScript
- JavaScript
You can use then
and catch
callbacks.
In TypeScript, you can also take advantage of the CustomerInfo
and WalletError
interfaces.
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
import { CustomerInfo } from '@paysafe/paysafe-wallet-saas-web/profile';
import { WalletError } from '@paysafe/paysafe-wallet-saas-web/errors';
Wallet.getInstance().getProfileService().getProfile()
.then((customerInfo: CustomerInfo) => console.log('Customer info', customerInfo))
.catch((error: WalletError) => console.error(error));
Try and catch blocks can also be used in combination with async/await.
import { CustomerInfo } from '@paysafe/paysafe-wallet-saas-web/profile';
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
try {
const customerInfo: CustomerInfo = await Wallet.getInstance().getProfileService().getProfile();
console.log('Customer info', customerInfo);
} catch (error) {
console.error(error);
}
You can use then
and catch
callbacks.
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
Wallet.getInstance().getProfileService().getProfile()
.then(customerInfo => console.log('Customer info', customerInfo))
.catch(error => console.error(error));
Try and catch blocks can also be used in combination with async/await.
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
try {
const customerInfo = await Wallet.getInstance().getProfileService().getProfile();
console.log('Customer info', customerInfo);
} catch (error) {
console.error(error);
}