Response format

Konbert's API uses a consistent format for responses, making it easy to handle both successes and failures in your code.

Responses will always be in JSON format, unless otherwise specified.

Successful Responses

When your request hits the mark, you'll get a 200 status code (or another 2xx code) and a JSON response that looks like this:

{
"status": "ok",
"http_status": 200,
"error": null,
"data": {
// The good stuff you requested
}
}

When Things Go South

If something goes wrong, you'll get an appropriate HTTP status code (usually 4xx or 5xx) and a JSON response that looks like this:

{
"status": "error",
"http_status": 400, // or whatever fits the situation
"error": {
"type": "what_went_wrong",
"message": "A human-friendly explanation",
"details": {
// More info about the error, if available
}
},
"data": null
}

Common Hiccups

Here are some error types you might run into:

  • validation_error: Your request data missed the mark or is incomplete.
  • authentication_error: Your API key is MIA or invalid.
  • rate_limit_exceeded: Whoa there! You've hit your API rate limit.
  • server_error: Oops, something went wrong on our end.

Dealing with Errors Like a Pro

When you're working with the Konbert API, always keep an eye on the "status" field. If it's "error", it's time to handle it in your app. The "message" field gives you a human-readable explanation, perfect for debugging or showing to your users.

Error Handling: A JavaScript Example

async function makeApiRequest() {
try {
const response = await fetch('https://konbert.com/api/v1/convert', {
// Your request options go here
});
const data = await response.json();
if (data.status === 'error') {
console.error(`Uh-oh! API Error: ${data.error.message}`);
// Handle the error in your app
} else {
// All good! Process the successful response
console.log(data.data);
}
} catch (error) {
console.error('Network hiccup:', error);
}
}

By staying on top of errors, you'll make your app more robust and give your users a smoother ride when using the Konbert API. Happy coding!