Monorepo for Tangled
0

Configure Feed

Select the types of activity you want to include in your feed.

bobbin/xrpc: return xrpc error bodies for unknown and mismatched methods

Signed-off-by: teq <teqed@shatteredsky.net>

quilling.dev (Jul 14, 2026, 3:02 PM EDT) cd41df6a fdafaa66

+23 -1
+23 -1
bobbin/crates/xrpc/src/lib.rs
··· 11 11 body::Body, 12 12 extract::{FromRequestParts, Query, RawQuery, State, rejection::QueryRejection}, 13 13 http::{ 14 - HeaderMap, HeaderName, StatusCode, 14 + HeaderMap, HeaderName, StatusCode, Uri, 15 15 header::{ 16 16 ACCEPT_RANGES, CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_LENGTH, 17 17 CONTENT_RANGE, CONTENT_TYPE, ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, ··· 389 389 get(resolve_mini_doc), 390 390 ) 391 391 .merge(knot_proxied_routes()) 392 + .fallback(fallback) 393 + .method_not_allowed_fallback(method_not_allowed) 392 394 .layer( 393 395 TraceLayer::new_for_http() 394 396 .make_span_with(DefaultMakeSpan::new().level(Level::INFO)) ··· 397 399 .on_failure(LatencyFreeTrace), 398 400 ) 399 401 .with_state(state) 402 + } 403 + 404 + async fn fallback(uri: Uri) -> Response { 405 + if uri.path().starts_with("/xrpc/") { 406 + let body = ErrorBody { 407 + error: "MethodNotImplemented", 408 + message: "method not implemented".into(), 409 + }; 410 + (StatusCode::NOT_IMPLEMENTED, Json(body)).into_response() 411 + } else { 412 + StatusCode::NOT_FOUND.into_response() 413 + } 414 + } 415 + 416 + async fn method_not_allowed() -> Response { 417 + let body = ErrorBody { 418 + error: "MethodNotAllowed", 419 + message: "method not allowed".into(), 420 + }; 421 + (StatusCode::METHOD_NOT_ALLOWED, Json(body)).into_response() 400 422 } 401 423 402 424 #[derive(Clone, Copy, Debug)]