Error Handling
Learn how to handle errors returned by the Fineract API.
HTTP Status Codes
Fineract uses conventional HTTP response codes to indicate the success or failure of an API request.
| Code | Status | Description |
|---|---|---|
| 200 | OK | Request succeeded |
| 400 | Bad Request | Invalid request parameters |
| 401 | Unauthorized | Invalid or missing authentication |
| 403 | Forbidden | Insufficient permissions |
| 404 | Not Found | Resource doesn't exist |
| 500 | Server Error | Internal server error |
Error Response Format
When an error occurs, Fineract returns a JSON object with details about what went wrong.
json
{
"developerMessage": "The request body is missing a required field",
"httpStatusCode": "400",
"defaultUserMessage": "Validation errors exist.",
"userMessageGlobalisationCode": "validation.msg.validation.errors.exist",
"errors": [
{
"developerMessage": "The parameter 'firstname' is mandatory.",
"defaultUserMessage": "The parameter 'firstname' is mandatory.",
"userMessageGlobalisationCode": "validation.msg.client.firstname.cannot.be.blank",
"parameterName": "firstname"
}
]
}Handling Errors in Code
Here's how to properly handle errors in your application:
javascript
async function createClient(clientData) {
try {
const response = await fetch(
"https://your-fineract-instance.com/fineract-provider/api/v1/clients",
{
method: "POST",
headers: {
"Authorization": `Basic ${credentials}`,
"Fineract-Platform-TenantId": "default",
"Content-Type": "application/json",
},
body: JSON.stringify(clientData),
}
);
if (!response.ok) {
const error = await response.json();
// Handle validation errors
if (error.errors && error.errors.length > 0) {
error.errors.forEach(err => {
console.error(`${err.parameterName}: ${err.defaultUserMessage}`);
});
}
throw new Error(error.defaultUserMessage);
}
return await response.json();
} catch (error) {
console.error("Failed to create client:", error.message);
throw error;
}
}Was this page helpful?