Skip to main content

Error Handling

Learn how to handle errors when using the TempsReel API.

Error Response Format

All errors follow the RFC 7807 Problem Details format:

{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"detail": "The x-tenant header is required",
"traceId": "00-abc123-def456-00"
}

HTTP Status Codes

400 Bad Request

Invalid request parameters or missing required headers.

{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"detail": "dateFrom must be less than or equal to dateTo"
}

Common causes:

  • Missing x-tenant header
  • Invalid date format
  • Invalid parameter values
  • Validation errors

404 Not Found

The requested resource doesn't exist.

{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
"title": "Not Found",
"status": 404,
"detail": "The requested resource was not found"
}

429 Too Many Requests

Rate limit exceeded. See Rate Limits for details.

{
"type": "https://tools.ietf.org/html/rfc6585#section-4",
"title": "Too Many Requests",
"status": 429,
"detail": "Rate limit exceeded. Please retry after 60 seconds."
}

500 Internal Server Error

Server-side error. Include the traceId when reporting issues.

{
"type": "https://tools.ietf.org/html/rfc7231#section-6.6.1",
"title": "Internal Server Error",
"status": 500,
"detail": "An unexpected error occurred",
"traceId": "00-abc123-def456-00"
}

Business Error Codes

Some endpoints return business-specific error codes in addition to HTTP status codes. Check the endpoint documentation for specific error codes.

Error Handling Best Practices

1. Always Check Response Status

const response = await fetch(url, options);
if (!response.ok) {
const error = await response.json();
// Handle error
}

2. Implement Retry Logic

For transient errors (500, 503), implement exponential backoff:

async function fetchWithRetry(url, options, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url, options);
if (response.ok) return response;

if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After');
await sleep(parseInt(retryAfter) * 1000);
continue;
}

if (response.status >= 500 && i < maxRetries - 1) {
await sleep(Math.pow(2, i) * 1000); // Exponential backoff
continue;
}

throw new Error(`Request failed: ${response.status}`);
} catch (error) {
if (i === maxRetries - 1) throw error;
}
}
}

3. Log Errors Appropriately

Always log the traceId for server errors:

if (error.status >= 500) {
console.error('Server error:', {
status: error.status,
detail: error.detail,
traceId: error.traceId
});
}

4. Handle Specific Error Types

switch (error.status) {
case 400:
// Show user-friendly validation message
showError(error.detail);
break;
case 404:
// Resource not found - handle gracefully
showNotFound();
break;
case 429:
// Rate limit - implement backoff
scheduleRetry(error);
break;
default:
// Unexpected error
logError(error);
showGenericError();
}

Code Examples

C#

try
{
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
var data = await response.Content.ReadFromJsonAsync<T>();
return data;
}
catch (HttpRequestException ex) when (ex.Data.Contains("StatusCode"))
{
var statusCode = (HttpStatusCode)ex.Data["StatusCode"];
if (statusCode == HttpStatusCode.BadRequest)
{
var error = await response.Content.ReadFromJsonAsync<ProblemDetails>();
throw new ValidationException(error.Detail);
}
throw;
}

Python

import requests

try:
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 400:
error = e.response.json()
raise ValidationError(error['detail'])
raise

Next Steps