import {
SDKError,
AuthenticationError,
NetworkError,
ValidationError,
ConfigurationError,
} from "yieldfi-sdk";
async function handleApiCall() {
try {
const vault = await sdk.vault.getVaultByKey("yusd", 1);
return vault;
} catch (error) {
if (error instanceof AuthenticationError) {
// Handle authentication errors
console.error("Authentication failed:", error.message);
// Redirect to login or refresh token
return null;
} else if (error instanceof NetworkError) {
// Handle network errors
console.error("Network error:", error.message);
if (error.statusCode === 503) {
// Service unavailable - show retry option
return { retry: true };
}
// Show error message to user
return null;
} else if (error instanceof ValidationError) {
// Handle validation errors
console.error("Invalid input:", error.message);
// Show validation error to user
return null;
} else if (error instanceof ConfigurationError) {
// Handle configuration errors
console.error("SDK configuration error:", error.message);
// This should not happen in production
return null;
} else if (error instanceof SDKError) {
// Handle other SDK errors
console.error("SDK error:", error.code, error.message);
return null;
} else {
// Handle unexpected errors
console.error("Unexpected error:", error);
return null;
}
}
}