Skip to content

API Update: 2023-04-14

Summary

All errors in the API are now being handled, processed, and logged in the admin. The API is also returning a JSON response with a 200 status code for errors. The response format for errors is as follows:

{"status": false, "detail": {"email": "Duplicate"}, "add_data": {...}}

Details

If an error occurs, the API will now return a JSON response with a 200 status code, rather than a different HTTP status code. The response will include a "status" field with a value of "false" "true" or "hold", a "detail" field with a dictionary of error details (in this example, the "email" field is set to "Duplicate"), and an "add_data" field with the request POST data. This format allows clients to handle errors more gracefully and with more information than just an HTTP status code.

In addition to returning a JSON response, all errors in the API are now being logged in the admin. This includes the error message, the request method, URL, headers, and payload. The logs will be stored in the admin for debugging purposes.

Example Code

Here's an example of how to handle an error in Python using the new JSON format:

import requests

response = requests.post("https://mcraftdb.tech/api/v1/dispatch", data=data, headers=headers).json()
if response["status"] == False:
    error_details = response.get("detail", {})
    # Handle the error details here...
else:
    # Process the response as usual...