Error Handling
The API uses standard HTTP status codes and consistent error response format.
HTTP Status Codes
Success Codes
200 OK- Successful request201 Created- Resource created successfully204 No Content- Successful deletion (no response body)
Client Error Codes
400 Bad Request- Invalid request (missing fields, invalid data)404 Not Found- Resource not found409 Conflict- Resource conflict (e.g., duplicate project path)
Server Error Codes
500 Internal Server Error- Server error
Error Response Format
All error responses follow this format:
{
"error": "Error message describing what went wrong"
}
Common Errors
400 Bad Request
Missing Required Fields:
{
"error": "Name and path are required"
}
Invalid Path:
{
"error": "Path does not exist"
}
Path Not Directory:
{
"error": "Path must be a directory"
}
Invalid Project ID:
{
"error": "Invalid project ID"
}
No Fields to Update:
{
"error": "No valid fields to update"
}
Missing Setting Value:
{
"error": "Value is required"
}
404 Not Found
Project Not Found:
{
"error": "Project not found"
}
409 Conflict
Duplicate Project Path:
{
"error": "Project with this path already exists",
"project": { /* existing project */ }
}
500 Internal Server Error
Generic Server Error:
{
"error": "Failed to fetch projects"
}
Specific Error:
{
"error": "Detailed error message"
}
Error Handling in Clients
JavaScript/TypeScript
async function addProject(name: string, path: string) {
try {
const response = await fetch('http://localhost:38124/api/projects', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name, path })
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error);
}
return await response.json();
} catch (error) {
console.error('Failed to add project:', error.message);
throw error;
}
}
cURL
# Check for errors
response=$(curl -s -w "\n%{http_code}" http://localhost:38124/api/projects/999)
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" != "200" ]; then
echo "Error: $body"
fi
Best Practices
- Always check HTTP status codes before processing response
- Read error messages from the
errorfield - Handle specific error codes appropriately (e.g., 404 vs 409)
- Log errors for debugging
- Provide user-friendly messages based on error types
Related Documentation
- Endpoints - Complete endpoint reference
- Integration - Integration examples