Class: ClaudeAgentServer::Middleware::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_agent_server/middleware/error_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



8
9
10
# File 'lib/claude_agent_server/middleware/error_handler.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/claude_agent_server/middleware/error_handler.rb', line 12

def call(env)
  @app.call(env)
rescue ServerError => e
  problem_response(e.status_code, e.to_problem_details)
rescue ClaudeAgentSDK::CLINotFoundError => e
  problem_response(503, problem(503, 'cli_not_found', 'CLI Not Found', e.message))
rescue ClaudeAgentSDK::CLIConnectionError => e
  problem_response(502, problem(502, 'cli_connection_error', 'CLI Connection Error', e.message))
rescue ClaudeAgentSDK::ProcessError => e
  problem_response(502, problem(502, 'cli_process_error', 'CLI Process Error', e.message))
rescue ClaudeAgentSDK::ClaudeSDKError => e
  problem_response(502, problem(502, 'sdk_error', 'SDK Error', e.message))
rescue ArgumentError => e
  problem_response(400, problem(400, 'invalid_request', 'Invalid Request', e.message))
rescue StandardError => e
  problem_response(500, problem(500, 'internal_error', 'Internal Error', e.message))
end