Error handling
Every method can throw LinaPayError — a single typed exception class
shared across every call in the SDK.
class LinaPayError extends Error {
message: string
statusCode?: number // present for HTTP failures
originalError?: unknown // the underlying cause, if any
}Catching errors
import { LinaPayError, createConsent } from 'react-native-lina-pay-sdk'
try {
const consent = await createConsent(credentials, payload)
} catch (error) {
if (error instanceof LinaPayError) {
// Validation errors have no statusCode
if (!error.statusCode) {
console.error('Validation error:', error.message)
// e.g. "payment.value must be greater than zero"
// e.g. "payment.creditor.cpfCnpj must be a valid CPF or CNPJ"
return
}
switch (error.statusCode) {
case 400:
console.error('Invalid payload:', error.message)
break
case 401:
case 403:
console.error('Invalid credentials')
break
case 500:
console.error('Server error')
break
default:
console.error('Error:', error.message)
}
}
}When it's thrown
| Situation | statusCode |
|---|---|
| Invalid credentials | 401 or 403 |
| Network error (timeout, no connection) | (none) |
| Server error | 500+ |
| Missing or invalid required fields | (none — caught before the network call) |
| Invalid format (CPF/CNPJ, URL, date, amount) | (none — caught before the network call) |
Authentication
The SDK manages OAuth2 authentication with the IAM server automatically: the access token is fetched with your credentials, cached, and refreshed about 5 minutes before it actually expires — you never call the auth endpoint yourself.
Next steps
- React Native SDK overview — requirements and configuration.
- Payment flow — the flow these errors most commonly surface in.