Skip to main content

Error Handling API Reference

This document provides comprehensive API reference for the Error Handling System.

Overview

The Error Handling API provides endpoints for managing errors, collecting user feedback, tracking analytics, and generating reports.

Base URL

/errors

Authentication

All endpoints require authentication. Include the authorization header:

Authorization: Bearer <your-token>

Error Handling Endpoints

Handle Error

Handle an error and return user-friendly response.

Endpoint: POST /errors/handle

Request Body:

{
"error_message": "Vector store connection failed",
"error_type": "ConnectionError",
"context": {
"user_id": "user123",
"session_id": "session456",
"query": "How to configure the API?",
"component": "vector_store",
"metadata": {
"additional_info": "any additional context"
}
}
}

Response:

{
"error_id": "error_12345",
"category": "retrieval_failure",
"severity": "medium",
"title": "Unable to Find Information",
"message": "I'm having trouble accessing the knowledge base to answer your question.",
"explanation": "This usually happens when the search system is temporarily unavailable.",
"suggested_actions": ["retry", "reformat_input", "contact_support"],
"workarounds": [
"Try rephrasing your question with different keywords",
"Wait a moment and try again"
],
"escalation_required": false,
"recovery_suggestions": [
"Check your internet connection",
"Try a simpler question"
],
"support_ticket_id": null,
"technical_details": null
}

Submit Error Feedback

Submit user feedback on error message helpfulness.

Endpoint: POST /errors/feedback

Request Body:

{
"error_id": "error_12345",
"user_id": "user123",
"helpful": true,
"comments": "The error message was very clear and helpful"
}

Response:

{
"message": "Feedback submitted successfully"
}

Track Error Resolution

Track error resolution for analytics.

Endpoint: POST /errors/resolution

Request Body:

{
"error_id": "error_12345",
"resolution_method": "retry_with_different_parameters",
"resolution_time_minutes": 5.0,
"success": true
}

Response:

{
"message": "Resolution tracked successfully"
}

Analytics Endpoints

Get Error Analytics

Get error metrics and statistics.

Endpoint: GET /errors/analytics

Query Parameters:

  • time_window_hours (optional): Time window in hours (default: 24)
  • category (optional): Filter by error category
  • severity (optional): Filter by error severity

Example:

GET /errors/analytics?time_window_hours=48&category=retrieval_failure

Response:

{
"total_errors": 150,
"errors_by_category": {
"retrieval_failure": 45,
"generation_timeout": 30,
"permission_denied": 15,
"rate_limit_exceeded": 25,
"network_error": 20,
"data_not_found": 15
},
"errors_by_severity": {
"low": 30,
"medium": 80,
"high": 35,
"critical": 5
},
"errors_by_component": {
"vector_store": 45,
"generation": 30,
"authorization": 15,
"rate_limiter": 25,
"network": 20,
"ui": 15
},
"error_trends": {
"trend": "increasing",
"recent_hourly_avg": 6.25,
"earlier_hourly_avg": 4.5,
"change_percentage": 38.9
},
"user_satisfaction": {
"overall_satisfaction": 0.82,
"total_feedback": 120,
"retrieval_failure_satisfaction": 0.85,
"generation_timeout_satisfaction": 0.78
},
"average_resolution_time": 12.5,
"peak_error_times": ["14:00", "10:00", "16:00"],
"top_error_patterns": [
{
"pattern": "retrieval_failure_medium",
"count": 45,
"percentage": 30.0
},
{
"pattern": "generation_timeout_medium",
"count": 30,
"percentage": 20.0
}
]
}

Get Error Insights

Get actionable insights from error analysis.

Endpoint: GET /errors/insights

Query Parameters:

  • time_window_hours (optional): Time window in hours (default: 24)

Response:

[
{
"insight_id": "insight_1",
"insight_type": "high_error_rate",
"title": "High Error Rate Detected",
"description": "System has experienced 150 errors in the last 24 hours",
"severity": "high",
"recommended_actions": [
"Investigate system health and performance",
"Check for recent deployments or changes",
"Review error patterns for common causes"
],
"impact_score": 0.8,
"confidence": 0.9
},
{
"insight_id": "insight_2",
"insight_type": "low_satisfaction",
"title": "Low User Satisfaction with Error Messages",
"description": "User satisfaction rate is 82%",
"severity": "medium",
"recommended_actions": [
"Review and improve error message clarity",
"Gather more user feedback",
"Test error messages with users"
],
"impact_score": 0.7,
"confidence": 0.8
}
]

Generate Error Report

Generate comprehensive error report.

Endpoint: GET /errors/report

Query Parameters:

  • report_type (optional): Type of report (default: "daily")
  • time_window_hours (optional): Time window in hours (default: 24)

Response:

{
"report_id": "report_12345",
"report_type": "daily",
"time_period": {
"start": "2024-01-15T00:00:00Z",
"end": "2024-01-15T23:59:59Z",
"duration_hours": 24
},
"summary": {
"total_errors": 150,
"most_common_category": "retrieval_failure",
"most_common_severity": "medium",
"overall_satisfaction": 0.82,
"average_resolution_time": 12.5,
"trend": "increasing"
},
"insights": [
{
"insight_id": "insight_1",
"insight_type": "high_error_rate",
"title": "High Error Rate Detected",
"description": "System has experienced 150 errors in the last 24 hours",
"severity": "high",
"recommended_actions": [
"Investigate system health and performance",
"Check for recent deployments or changes"
],
"impact_score": 0.8,
"confidence": 0.9
}
],
"recommendations": [
"Investigate system health and performance issues",
"Improve error message clarity and user guidance",
"Monitor error trends and implement preventive measures"
],
"generated_at": "2024-01-15T12:00:00Z"
}

Get Dashboard Data

Get data formatted for dashboard visualization.

Endpoint: GET /errors/dashboard

Query Parameters:

  • time_window_hours (optional): Time window in hours (default: 24)

Response:

{
"overview": {
"total_errors": 150,
"error_trend": "increasing",
"user_satisfaction": 0.82,
"average_resolution_time": 12.5
},
"charts": {
"errors_by_category": [
{"category": "retrieval_failure", "count": 45},
{"category": "generation_timeout", "count": 30},
{"category": "permission_denied", "count": 15}
],
"errors_by_severity": [
{"severity": "low", "count": 30},
{"severity": "medium", "count": 80},
{"severity": "high", "count": 35}
],
"errors_by_component": [
{"component": "vector_store", "count": 45},
{"component": "generation", "count": 30},
{"component": "authorization", "count": 15}
]
},
"insights": [
{
"title": "High Error Rate Detected",
"description": "System has experienced 150 errors in the last 24 hours",
"severity": "high",
"recommended_actions": [
"Investigate system health and performance",
"Check for recent deployments or changes"
]
}
],
"top_error_patterns": [
{
"pattern": "retrieval_failure_medium",
"count": 45,
"percentage": 30.0
}
],
"peak_error_times": ["14:00", "10:00", "16:00"]
}

Export Endpoints

Export Metrics

Export error metrics to JSON.

Endpoint: GET /errors/export/metrics

Query Parameters:

  • time_window_hours (optional): Time window in hours (default: 24)

Response: JSON file download

Export Report

Export error report to JSON.

Endpoint: GET /errors/export/report

Query Parameters:

  • report_type (optional): Type of report (default: "daily")
  • time_window_hours (optional): Time window in hours (default: 24)

Response: JSON file download

Health Check

Error Handling Health

Check health of error handling system.

Endpoint: GET /errors/health

Response:

{
"status": "healthy",
"error_handler": "initialized",
"analytics_dashboard": "initialized",
"timestamp": "2024-01-15T12:00:00Z"
}

Error Categories

CategoryDescription
retrieval_failureIssues accessing knowledge base
generation_timeoutResponse generation taking too long
permission_deniedAccess restrictions
rate_limit_exceededToo many requests
authentication_failedLogin/session issues
network_errorConnection problems
data_not_foundNo relevant information found
configuration_errorSystem configuration issues
unknown_errorUnclassified errors

Error Severity Levels

SeverityDescription
lowMinor issues, minimal impact
mediumModerate issues, some user impact
highSignificant issues, major user impact
criticalSystem-breaking issues, immediate attention required

Resolution Actions

ActionDescription
retryTry the operation again
reformat_inputModify the input format
contact_supportContact human support
check_permissionsVerify user permissions
wait_and_retryWait before retrying
use_alternativeUse an alternative approach
escalateEscalate to higher level support

HTTP Status Codes

CodeDescription
200Success
400Bad Request - Invalid input
401Unauthorized - Authentication required
403Forbidden - Insufficient permissions
404Not Found - Resource not found
500Internal Server Error - Server error
503Service Unavailable - Service temporarily unavailable

Rate Limiting

The API implements rate limiting to ensure fair usage:

  • Error Handling: 100 requests per minute per user
  • Analytics: 50 requests per minute per user
  • Export: 10 requests per minute per user

Rate limit headers are included in responses:

  • X-RateLimit-Limit: Maximum requests allowed
  • X-RateLimit-Remaining: Remaining requests in current window
  • X-RateLimit-Reset: Time when the rate limit resets

Error Responses

When an error occurs, the API returns a JSON response with error details:

{
"error": "Error message",
"error_code": "ERROR_CODE",
"details": "Additional error details",
"timestamp": "2024-01-15T12:00:00Z"
}

SDK Examples

Python

import requests

# Handle an error
response = requests.post('/errors/handle', json={
'error_message': 'Vector store connection failed',
'error_type': 'ConnectionError',
'context': {
'user_id': 'user123',
'query': 'How to configure the API?',
'component': 'vector_store'
}
})

error_data = response.json()
print(f"Error message: {error_data['message']}")
print(f"Suggested actions: {error_data['suggested_actions']}")

# Submit feedback
requests.post('/errors/feedback', json={
'error_id': error_data['error_id'],
'user_id': 'user123',
'helpful': True,
'comments': 'Very helpful message'
})

# Get analytics
analytics = requests.get('/errors/analytics?time_window_hours=24').json()
print(f"Total errors: {analytics['total_errors']}")

JavaScript

// Handle an error
const errorResponse = await fetch('/errors/handle', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({
error_message: 'Vector store connection failed',
error_type: 'ConnectionError',
context: {
user_id: 'user123',
query: 'How to configure the API?',
component: 'vector_store'
}
})
});

const errorData = await errorResponse.json();
console.log('Error message:', errorData.message);
console.log('Suggested actions:', errorData.suggested_actions);

// Submit feedback
await fetch('/errors/feedback', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({
error_id: errorData.error_id,
user_id: 'user123',
helpful: true,
comments: 'Very helpful message'
})
});

// Get analytics
const analytics = await fetch('/errors/analytics?time_window_hours=24').then(r => r.json());
console.log('Total errors:', analytics.total_errors);

Webhooks

The API supports webhooks for real-time notifications:

Error Escalation Webhook

Triggered when an error is escalated to human support.

URL: POST /webhooks/error-escalation

Payload:

{
"error_id": "error_12345",
"support_ticket_id": "TICKET-ABC123",
"category": "permission_denied",
"severity": "high",
"user_id": "user123",
"timestamp": "2024-01-15T12:00:00Z"
}

High Error Rate Alert Webhook

Triggered when error rate exceeds threshold.

URL: POST /webhooks/high-error-rate

Payload:

{
"error_count": 150,
"threshold": 100,
"time_window_hours": 24,
"timestamp": "2024-01-15T12:00:00Z"
}

Changelog

Version 1.0.0

  • Initial release
  • Error classification and user-friendly messaging
  • Analytics and reporting
  • A/B testing framework
  • User feedback collection
  • Escalation management