@@ -17,6 +17,7 @@ pub type AtpSession = crate::com::atproto::server::create_session::Output;
1717pub struct CredentialSession < S , T >
1818where
1919 S : MapStore < ( ) , AtpSession > + Send + Sync ,
20+ S :: Error : Send + Sync + ' static ,
2021 T : XrpcClient + Send + Sync ,
2122{
2223 store : Arc < inner:: Store < S > > ,
2728impl < S , T > CredentialSession < S , T >
2829where
2930 S : MapStore < ( ) , AtpSession > + Send + Sync ,
31+ S :: Error : Send + Sync + ' static ,
3032 T : XrpcClient + Send + Sync ,
3133{
3234 pub fn new ( xrpc : T , store : S ) -> Self {
5860 . into ( ) ,
5961 )
6062 . await ?;
61- self . store . set ( ( ) , result. clone ( ) ) . await . expect ( "todo" ) ;
63+ self . store . set ( ( ) , result. clone ( ) ) . await . map_err ( |e| Error :: SessionStore ( Box :: new ( e ) ) ) ? ;
6264 if let Some ( did_doc) = result
6365 . did_doc
6466 . as_ref ( )
@@ -73,17 +75,22 @@ where
7375 & self ,
7476 session : AtpSession ,
7577 ) -> Result < ( ) , Error < crate :: com:: atproto:: server:: get_session:: Error > > {
76- self . store . set ( ( ) , session. clone ( ) ) . await . expect ( "todo" ) ;
78+ self . store . set ( ( ) , session. clone ( ) ) . await . map_err ( |e| Error :: SessionStore ( Box :: new ( e ) ) ) ? ;
7779 let result = self . api . com . atproto . server . get_session ( ) . await ;
7880 match result {
7981 Ok ( output) => {
8082 assert_eq ! ( output. data. did, session. data. did) ;
81- if let Some ( mut session) = self . store . get ( & ( ) ) . await . expect ( "todo" ) {
83+ if let Some ( mut session) =
84+ self . store . get ( & ( ) ) . await . map_err ( |e| Error :: SessionStore ( Box :: new ( e) ) ) ?
85+ {
8286 session. did_doc = output. data . did_doc . clone ( ) ;
8387 session. email = output. data . email ;
8488 session. email_confirmed = output. data . email_confirmed ;
8589 session. handle = output. data . handle ;
86- self . store . set ( ( ) , session) . await . expect ( "todo" ) ;
90+ self . store
91+ . set ( ( ) , session)
92+ . await
93+ . map_err ( |e| Error :: SessionStore ( Box :: new ( e) ) ) ?;
8794 }
8895 if let Some ( did_doc) = output
8996 . data
96103 Ok ( ( ) )
97104 }
98105 Err ( err) => {
99- self . store . clear ( ) . await . expect ( "todo" ) ;
106+ self . store . clear ( ) . await . map_err ( |e| Error :: SessionStore ( Box :: new ( e ) ) ) ? ;
100107 Err ( err)
101108 }
102109 }
@@ -125,7 +132,7 @@ where
125132 }
126133 /// Get the current session.
127134 pub async fn get_session ( & self ) -> Option < AtpSession > {
128- self . store . get ( & ( ) ) . await . expect ( "todo" )
135+ self . store . get ( & ( ) ) . await . transpose ( ) . and_then ( Result :: ok )
129136 }
130137 /// Get the current endpoint.
131138 pub async fn get_endpoint ( & self ) -> String {
@@ -146,6 +153,7 @@ where
146153pub struct AtpAgent < S , T >
147154where
148155 S : MapStore < ( ) , AtpSession > + Send + Sync ,
156+ S :: Error : Send + Sync + ' static ,
149157 T : XrpcClient + Send + Sync ,
150158{
151159 inner : CredentialSession < S , T > ,
@@ -154,6 +162,7 @@ where
154162impl < S , T > AtpAgent < S , T >
155163where
156164 S : MapStore < ( ) , AtpSession > + Send + Sync ,
165+ S :: Error : Send + Sync + ' static ,
157166 T : XrpcClient + Send + Sync ,
158167{
159168 /// Create a new agent.
@@ -165,6 +174,7 @@ where
165174impl < S , T > Deref for AtpAgent < S , T >
166175where
167176 S : MapStore < ( ) , AtpSession > + Send + Sync ,
177+ S :: Error : Send + Sync + ' static ,
168178 T : XrpcClient + Send + Sync ,
169179{
170180 type Target = CredentialSession < S , T > ;
@@ -365,7 +375,11 @@ mod tests {
365375 ..Default :: default ( )
366376 } ;
367377 let agent = AtpAgent :: new ( client, MemoryMapStore :: default ( ) ) ;
368- agent. store . set ( ( ) , session_data. clone ( ) . into ( ) ) . await . expect ( "todo" ) ;
378+ agent
379+ . store
380+ . set ( ( ) , session_data. clone ( ) . into ( ) )
381+ . await
382+ . expect ( "set session should be succeeded" ) ;
369383 let output = agent
370384 . api
371385 . com
@@ -399,7 +413,11 @@ mod tests {
399413 ..Default :: default ( )
400414 } ;
401415 let agent = AtpAgent :: new ( client, MemoryMapStore :: default ( ) ) ;
402- agent. store . set ( ( ) , session_data. clone ( ) . into ( ) ) . await . expect ( "todo" ) ;
416+ agent
417+ . store
418+ . set ( ( ) , session_data. clone ( ) . into ( ) )
419+ . await
420+ . expect ( "set session should be succeeded" ) ;
403421 let output = agent
404422 . api
405423 . com
@@ -410,7 +428,12 @@ mod tests {
410428 . expect ( "get session should be succeeded" ) ;
411429 assert_eq ! ( output. did. as_str( ) , "did:web:example.com" ) ;
412430 assert_eq ! (
413- agent. store. get( & ( ) ) . await . expect( "todo" ) . map( |session| session. data. access_jwt) ,
431+ agent
432+ . store
433+ . get( & ( ) )
434+ . await
435+ . expect( "get session should be succeeded" )
436+ . map( |session| session. data. access_jwt) ,
414437 Some ( "access" . into( ) )
415438 ) ;
416439 }
@@ -438,7 +461,11 @@ mod tests {
438461 } ;
439462 let counts = Arc :: clone ( & client. counts ) ;
440463 let agent = Arc :: new ( AtpAgent :: new ( client, MemoryMapStore :: default ( ) ) ) ;
441- agent. store . set ( ( ) , session_data. clone ( ) . into ( ) ) . await . expect ( "todo" ) ;
464+ agent
465+ . store
466+ . set ( ( ) , session_data. clone ( ) . into ( ) )
467+ . await
468+ . expect ( "set session should be succeeded" ) ;
442469 let handles = ( 0 ..3 ) . map ( |_| {
443470 let agent = Arc :: clone ( & agent) ;
444471 tokio:: spawn ( async move { agent. api . com . atproto . server . get_session ( ) . await } )
@@ -453,7 +480,12 @@ mod tests {
453480 assert_eq ! ( output. did. as_str( ) , "did:web:example.com" ) ;
454481 }
455482 assert_eq ! (
456- agent. store. get( & ( ) ) . await . expect( "todo" ) . map( |session| session. data. access_jwt) ,
483+ agent
484+ . store
485+ . get( & ( ) )
486+ . await
487+ . expect( "get session should be succeeded" )
488+ . map( |session| session. data. access_jwt) ,
457489 Some ( "access" . into( ) )
458490 ) ;
459491 assert_eq ! (
0 commit comments