Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

proxy back upstream BadRequests

+43 -8
+2 -3
slingshot/src/record.rs
··· 58 59 #[derive(Debug, Deserialize)] 60 pub struct ErrorResponseObject { 61 - error: String, 62 - #[allow(dead_code)] 63 - message: String, 64 } 65 66 #[derive(Clone)]
··· 58 59 #[derive(Debug, Deserialize)] 60 pub struct ErrorResponseObject { 61 + pub error: String, 62 + pub message: String, 63 } 64 65 #[derive(Clone)]
+41 -5
slingshot/src/server.rs
··· 1 - use crate::{CachedRecord, Identity, Repo, error::ServerError}; 2 use atrium_api::types::string::{Cid, Did, Handle, Nsid, RecordKey}; 3 use foyer::HybridCache; 4 use serde::Serialize; ··· 201 202 let at_uri = format!("at://{}/{}/{}", &*did, &*collection, &*rkey); 203 204 - let entry = self 205 .cache 206 .fetch(at_uri.clone(), { 207 let cid = cid.clone(); ··· 213 .map_err(|e| foyer::Error::Other(Box::new(e))) 214 } 215 }) 216 - .await 217 - .unwrap(); // todo 218 219 - // TODO: actual 404 220 221 match *entry { 222 CachedRecord::Found(ref raw) => {
··· 1 + use crate::{ 2 + CachedRecord, ErrorResponseObject, Identity, Repo, 3 + error::{RecordError, ServerError}, 4 + }; 5 use atrium_api::types::string::{Cid, Did, Handle, Nsid, RecordKey}; 6 use foyer::HybridCache; 7 use serde::Serialize; ··· 204 205 let at_uri = format!("at://{}/{}/{}", &*did, &*collection, &*rkey); 206 207 + let fr = self 208 .cache 209 .fetch(at_uri.clone(), { 210 let cid = cid.clone(); ··· 216 .map_err(|e| foyer::Error::Other(Box::new(e))) 217 } 218 }) 219 + .await; 220 221 + let entry = match fr { 222 + Ok(e) => e, 223 + Err(foyer::Error::Other(e)) => { 224 + let record_error = match e.downcast::<RecordError>() { 225 + Ok(e) => e, 226 + Err(e) => { 227 + log::error!("error (foyer other) getting cache entry, {e:?}"); 228 + return GetRecordResponse::ServerError(xrpc_error( 229 + "ServerError", 230 + "sorry, something went wrong", 231 + )); 232 + } 233 + }; 234 + let RecordError::UpstreamBadRequest(ErrorResponseObject { error, message }) = 235 + *record_error 236 + else { 237 + log::error!("RecordError getting cache entry, {record_error:?}"); 238 + return GetRecordResponse::ServerError(xrpc_error( 239 + "ServerError", 240 + "sorry, something went wrong", 241 + )); 242 + }; 243 + return GetRecordResponse::BadRequest(xrpc_error( 244 + error, 245 + format!("Upstream bad request: {message}"), 246 + )); 247 + } 248 + Err(e) => { 249 + log::error!("error (foyer) getting cache entry, {e:?}"); 250 + return GetRecordResponse::ServerError(xrpc_error( 251 + "ServerError", 252 + "sorry, something went wrong", 253 + )); 254 + } 255 + }; 256 257 match *entry { 258 CachedRecord::Found(ref raw) => {