@@ -95,6 +95,14 @@ const PermissionResponsePayload = Schema.Struct({
9595 response : Permission . Reply ,
9696} ) . annotate ( { identifier : "SessionPermissionResponseInput" } )
9797
98+ const mapNotFound = < A , E , R > ( self : Effect . Effect < A , E , R > ) =>
99+ self . pipe (
100+ Effect . catchIf ( NotFoundError . isInstance , ( ) => Effect . fail ( new HttpApiError . NotFound ( { } ) ) ) ,
101+ Effect . catchDefect ( ( error ) =>
102+ NotFoundError . isInstance ( error ) ? Effect . fail ( new HttpApiError . NotFound ( { } ) ) : Effect . die ( error ) ,
103+ ) ,
104+ )
105+
98106export const SessionPaths = {
99107 list : root ,
100108 status : `${ root } /status` ,
@@ -150,6 +158,7 @@ export const SessionApi = HttpApi.make("session")
150158 HttpApiEndpoint . get ( "get" , SessionPaths . get , {
151159 params : { sessionID : SessionID } ,
152160 success : Session . Info ,
161+ error : HttpApiError . NotFound ,
153162 } ) . annotateMerge (
154163 OpenApi . annotations ( {
155164 identifier : "session.get" ,
@@ -203,6 +212,7 @@ export const SessionApi = HttpApi.make("session")
203212 HttpApiEndpoint . get ( "message" , SessionPaths . message , {
204213 params : { sessionID : SessionID , messageID : MessageID } ,
205214 success : MessageV2 . WithParts ,
215+ error : HttpApiError . NotFound ,
206216 } ) . annotateMerge (
207217 OpenApi . annotations ( {
208218 identifier : "session.message" ,
@@ -459,7 +469,7 @@ export const sessionHandlers = HttpApiBuilder.group(SessionApi, "session", (hand
459469 } )
460470
461471 const get = Effect . fn ( "SessionHttpApi.get" ) ( function * ( ctx : { params : { sessionID : SessionID } } ) {
462- return yield * session . get ( ctx . params . sessionID )
472+ return yield * mapNotFound ( session . get ( ctx . params . sessionID ) )
463473 } )
464474
465475 const children = Effect . fn ( "SessionHttpApi.children" ) ( function * ( ctx : { params : { sessionID : SessionID } } ) {
@@ -481,7 +491,7 @@ export const sessionHandlers = HttpApiBuilder.group(SessionApi, "session", (hand
481491 params : { sessionID : SessionID }
482492 query : typeof MessagesQuery . Type
483493 } ) {
484- return yield * Effect . gen ( function * ( ) {
494+ return yield * mapNotFound ( Effect . gen ( function * ( ) {
485495 if ( ctx . query . before && ctx . query . limit === undefined ) return yield * new HttpApiError . BadRequest ( { } )
486496 if ( ctx . query . before ) {
487497 const before = ctx . query . before
@@ -514,21 +524,14 @@ export const sessionHandlers = HttpApiBuilder.group(SessionApi, "session", (hand
514524 "X-Next-Cursor" : page . cursor ,
515525 } ,
516526 } )
517- } ) . pipe (
518- Effect . catchIf ( NotFoundError . isInstance , ( ) => Effect . fail ( new HttpApiError . NotFound ( { } ) ) ) ,
519- Effect . catchDefect ( ( error ) =>
520- NotFoundError . isInstance ( error )
521- ? Effect . fail ( new HttpApiError . NotFound ( { } ) )
522- : Effect . die ( error ) ,
523- ) ,
524- )
527+ } ) )
525528 } )
526529
527530 const message = Effect . fn ( "SessionHttpApi.message" ) ( function * ( ctx : {
528531 params : { sessionID : SessionID ; messageID : MessageID }
529532 } ) {
530- return yield * Effect . sync ( ( ) =>
531- MessageV2 . get ( { sessionID : ctx . params . sessionID , messageID : ctx . params . messageID } ) ,
533+ return yield * mapNotFound (
534+ Effect . sync ( ( ) => MessageV2 . get ( { sessionID : ctx . params . sessionID , messageID : ctx . params . messageID } ) ) ,
532535 )
533536 } )
534537
0 commit comments