1- use crate :: { CachedRecord , Identity , Repo , error:: ServerError } ;
1+ use crate :: {
2+ CachedRecord , ErrorResponseObject , Identity , Repo ,
3+ error:: { RecordError , ServerError } ,
4+ } ;
25use atrium_api:: types:: string:: { Cid , Did , Handle , Nsid , RecordKey } ;
36use foyer:: HybridCache ;
47use serde:: Serialize ;
@@ -201,7 +204,7 @@ impl Xrpc {
201204
202205 let at_uri = format ! ( "at://{}/{}/{}" , & * did, & * collection, & * rkey) ;
203206
204- let entry = self
207+ let fr = self
205208 . cache
206209 . fetch ( at_uri. clone ( ) , {
207210 let cid = cid. clone ( ) ;
@@ -213,10 +216,43 @@ impl Xrpc {
213216 . map_err ( |e| foyer:: Error :: Other ( Box :: new ( e) ) )
214217 }
215218 } )
216- . await
217- . unwrap ( ) ; // todo
219+ . await ;
218220
219- // TODO: actual 404
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+ } ;
220256
221257 match * entry {
222258 CachedRecord :: Found ( ref raw) => {
0 commit comments