Skip to main content

Error Handling Guide

Guide in Progress

This guide is currently under development and may change as we improve our error handling standards.

Please note that error codes and messages are not yet fully consistent and may be updated without notice. Your feedback is welcome, but any changes you make could be overwritten in future updates.

Overview

The DeePsy API uses standard HTTP status codes combined with detailed error information to help you understand and handle errors effectively. All errors follow a consistent format and include specific error codes for programmatic handling.

Error Response Format

All API errors return a consistent JSON structure:

{
"error": "Human-readable error description",
"error_code": "MACHINE_READABLE_ERROR_CODE"
}

Example Error Response

{
"error": "You do not have the required permissions to access this resource",
"error_code": "INSUFFICIENT_PERMISSIONS"
}

Common Error Codes

Authentication Errors (401)

Error CodeDescriptionSolution
API_KEY_NOT_PROVIDEDNo API key in Authorization headerInclude Authorization: Bearer deepsy-dev-your-key
INVALID_API_KEY_FORMATAPI key format is incorrectEnsure key starts with deepsy-dev-
INVALID_API_KEYAPI key doesn't exist or is invalidCheck your API key in dashboard settings
API_KEY_INACTIVEAPI key has been deactivatedRegenerate your API key

Permission Errors (403)

Error CodeDescriptionSolution
USER_NOT_IN_COMPANYUser is not a member of the companyJoin the company or use correct company ID
NO_PERMISSIONS_FOUNDNo permissions for this companyContact company admin for permission grant
INSUFFICIENT_PERMISSIONSMissing required permissionsRequest additional permissions from admin

Missing Subscription/Credits Errors (402)

Error CodeDescriptionSolution
ACTIVE_SUBSCRIPTION_REQUIREDCompany subscription is inactiveRenew company subscription

Validation Errors (422)

Error CodeDescriptionSolution
NO_COMPANY_MEMBERSHIPUser must belong to at least one companyJoin a company before using the API

Specific Error Scenarios

Authentication Setup

async function setupAuthentication(apiKey) {
try {
const response = await fetch('https://deepsy.fr/api/v1/health', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});

if (!response.ok) {
const error = await response.json();

switch (error.error_code) {
case 'API_KEY_NOT_PROVIDED':
throw new Error('Please provide your API key');
case 'INVALID_API_KEY_FORMAT':
throw new Error('API key format is invalid. Check your key format.');
case 'INVALID_API_KEY':
throw new Error('API key is invalid. Please check your dashboard.');
case 'API_KEY_INACTIVE':
throw new Error('API key is inactive. Please regenerate it.');
default:
throw new Error(`Authentication failed: ${error.error}`);
}
}

return true;
} catch (error) {
console.error('Authentication setup failed:', error.message);
throw error;
}
}