MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / into_response

Method into_response

nodedb/src/control/server/http/auth.rs:162–193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

160
161impl IntoResponse for ApiError {
162 fn into_response(self) -> Response {
163 use super::types::HttpError;
164
165 match self {
166 ApiError::RateLimited {
167 message,
168 retry_after_secs,
169 } => {
170 let body = HttpError::new(message);
171 let mut resp = (StatusCode::TOO_MANY_REQUESTS, axum::Json(body)).into_response();
172 if let Ok(val) = retry_after_secs.to_string().parse() {
173 resp.headers_mut().insert("Retry-After", val);
174 }
175 resp
176 }
177 other => {
178 let (status, message) = match other {
179 ApiError::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg),
180 ApiError::Forbidden(msg) => (StatusCode::FORBIDDEN, msg),
181 ApiError::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg),
182 ApiError::Internal(msg) => (StatusCode::INTERNAL_SERVER_ERROR, msg),
183 ApiError::RateLimited { .. } => unreachable!(),
184 ApiError::HttpStatus(code, msg) => (
185 StatusCode::from_u16(code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
186 msg,
187 ),
188 };
189 let body = HttpError::new(message);
190 (status, axum::Json(body)).into_response()
191 }
192 }
193 }
194}
195
196/// Axum extractor that resolves and enforces HTTP auth before a handler runs.

Callers 8

startup_gate_middlewareFunction · 0.80
upload_wasmFunction · 0.80
json_responseFunction · 0.80
poll_changesFunction · 0.80
poll_streamFunction · 0.80
query_ndjsonFunction · 0.80
json_responseFunction · 0.80
remote_readFunction · 0.80

Calls 3

to_stringMethod · 0.80
parseMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected