MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / into_response

Method into_response

crates/opencode-server/src/error.rs:30–64  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

28
29impl IntoResponse for ApiError {
30 fn into_response(self) -> Response {
31 let (status, message, error_type) = match self {
32 ApiError::SessionNotFound(id) => (
33 StatusCode::NOT_FOUND,
34 format!("Session not found: {}", id),
35 "session_not_found",
36 ),
37 ApiError::NotFound(msg) => (StatusCode::NOT_FOUND, msg, "not_found"),
38 ApiError::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg, "bad_request"),
39 ApiError::ProviderError(msg) => (
40 StatusCode::BAD_GATEWAY,
41 format!("Provider error: {}", msg),
42 "provider_error",
43 ),
44 ApiError::InvalidRequest(msg) => (
45 StatusCode::BAD_REQUEST,
46 format!("Invalid request: {}", msg),
47 "invalid_request",
48 ),
49 ApiError::InternalError(msg) => (
50 StatusCode::INTERNAL_SERVER_ERROR,
51 format!("Internal error: {}", msg),
52 "internal_error",
53 ),
54 };
55
56 let body = Json(json!({
57 "error": {
58 "message": message,
59 "type": error_type
60 }
61 }));
62
63 (status, body).into_response()
64 }
65}
66
67pub type Result<T> = std::result::Result<T, ApiError>;

Callers 1

pty_connectFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected