File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,12 +10,7 @@ export interface ErrorResponse {
1010 } ;
1111}
1212
13- export const SerializeError = Effect . catchAll <
14- unknown ,
15- ErrorResponse ,
16- never ,
17- never
18- > ( ( error ) => {
13+ const formatError = ( error : unknown ) => {
1914 if ( error instanceof ParseError ) {
2015 const failures = ParseResult . ArrayFormatter . formatErrorSync ( error ) . map (
2116 ( failure ) => ( { path : failure . path . join ( '.' ) , message : failure . message } )
@@ -32,4 +27,15 @@ export const SerializeError = Effect.catchAll<
3227 return Effect . succeed ( {
3328 error : { message : 'Internal error' , tag : 'UnknownError' } ,
3429 } ) ;
35- } ) ;
30+ } ;
31+
32+ export const SerializeError = Effect . catchAll <
33+ unknown ,
34+ ErrorResponse ,
35+ never ,
36+ never
37+ > ( ( error ) => formatError ( error ) ) ;
38+
39+ export const ErrorHandler = Effect . catchAllDefect ( ( error ) =>
40+ formatError ( error )
41+ ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { onCallEffect } from '@effect-firebase/admin';
22import { Effect , Option } from 'effect' ;
33import { runtime } from './runtime.js' ;
44import { OnExampleCall , PostRepository } from '@example/shared' ;
5+ import { SerializeError , ErrorHandler } from './error-handler.js' ;
56
67/**
78 * Example using onCallEffect with schemas.
@@ -20,5 +21,5 @@ export const onExampleCall = onCallEffect(
2021 const posts = yield * PostRepository ;
2122 const post = yield * posts . getById ( input . id ) ;
2223 return Option . getOrThrow ( post ) ;
23- } )
24+ } ) . pipe ( SerializeError , ErrorHandler )
2425) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Effect, Option } from 'effect';
22import { onRequestEffect } from '@effect-firebase/admin' ;
33import { OnExampleRequest , PostId , PostRepository } from '@example/shared' ;
44import { runtime } from './runtime.js' ;
5+ import { SerializeError , ErrorHandler } from './error-handler.js' ;
56
67/**
78 * Example using onRequestEffect with schemas.
@@ -21,5 +22,5 @@ export const onExampleRequest = onRequestEffect(
2122 const id = PostId . make ( body . id ) ;
2223 const post = yield * posts . getById ( id ) ;
2324 return Option . getOrThrow ( post ) ;
24- } )
25+ } ) . pipe ( SerializeError , ErrorHandler )
2526) ;
You can’t perform that action at this time.
0 commit comments