Error Handling
The NXSYS API uses conventional HTTP response codes to indicate the success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information, and codes in the 5xx range indicate an error with NXSYS's servers.
HTTP Status Codes
Status Code | Description |
---|---|
200 | OK - The request was successful |
201 | Created - The resource was successfully created |
400 | Bad Request - The request was invalid or cannot be served |
401 | Unauthorized - Authentication credentials are missing or invalid |
403 | Forbidden - The authenticated user doesn't have access to the requested resource |
404 | Not Found - The requested resource doesn't exist |
422 | Unprocessable Entity - The request was well-formed but had semantic errors |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error - Something went wrong on our end |
Error Response Format
When an error occurs, the API returns a JSON response with the following structure:
{
"error": {
"code": "error_code",
"message": "Human readable error message",
"details": {
// Additional error details if available
}
}
}
Common Error Codes
Authentication Errors
invalid_credentials
: The provided API key is invalid or expiredmissing_credentials
: No API key was provided in the requestinsufficient_permissions
: The API key doesn't have the required permissions
Validation Errors
invalid_request
: The request payload is malformed or missing required fieldsinvalid_parameter
: One or more parameters in the request are invalidresource_not_found
: The requested resource doesn't exist
Example Error Handling
Here's an example of how to handle errors in different programming languages:
// JavaScript/Node.js
try {
const response = await fetch('https://dev-api.nxsys.tech/v1/resource');
if (!response.ok) {
const error = await response.json();
throw new Error(error.error.message);
}
const data = await response.json();
} catch (error) {
console.error('API Error:', error.message);
}