Command Palette

Search for a command to run...

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.

CodeStatusDescription
200OKRequest succeeded
400Bad RequestInvalid request parameters
401UnauthorizedInvalid or missing authentication
403ForbiddenInsufficient permissions
404Not FoundResource doesn't exist
500Server ErrorInternal 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?