Error
This section provides information on potential errors that may occur during API interactions and how to handle them.
Common error codes and descriptions
Code & Error
Description
400 Bad Request
The request is invalid or missing required parameters.
401 Unauthorized
Invalid API key or authentication credentials.
403 Forbidden
Insufficient permissions to access the resource.
404 Not Found
The requested resource was not found.
422 Unprocessable Entity
The request is well-formed but semantically incorrect.
500 Internal Server Error
An unexpected error occurred on the server.
Error handling strategies
1. Check HTTP Status Codes:
2. Parse Error Messages:
3.Retry Failed Requests:
4.Log Errors:
const myHeaders = new Headers();
myHeaders.append("token", "TlAWiePV51isvfuRZEHuCOW1ZDBeDHep2rnosIXHRVGvMwyFTMJZUVCeIneQJJ0h");
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
"customerId": "49438567-bc45-494c-b57d-80b41f193de7",
"currency": "kes",
"channel": "fiat"
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://api.switch.tulupay.com/customer/add-account", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
}
By implementing robust error handling, you can improve the reliability and user experience of your application.