@@ -22,28 +22,24 @@ export type NumericOrKeyedResponseType<R extends HttpRoute> =
2222export type ResponseEncoder = (
2323 route : HttpRoute ,
2424 serviceFnResponse : NumericOrKeyedResponseType < HttpRoute > ,
25- expressRes : express . Response ,
26- ) => void ;
25+ ) => express . RequestHandler ;
2726
28- export const defaultResponseEncoder : ResponseEncoder = (
29- route ,
30- serviceFnResponse ,
31- expressRes ,
32- ) => {
33- const { type, payload } = serviceFnResponse ;
34- const status = typeof type === 'number' ? type : ( KeyToHttpStatus as any ) [ type ] ;
35- if ( status === undefined ) {
36- console . warn ( 'Unknown status code returned' ) ;
37- expressRes . status ( 500 ) . end ( ) ;
38- return ;
39- }
40- const responseCodec = route . response [ status ] ;
41- try {
42- expressRes . status ( status ) . json ( responseCodec ! . encode ( payload ) ) . end ( ) ;
43- } catch {
44- console . warn (
45- "Unable to encode route's return value, did you return the expected type?" ,
46- ) ;
47- expressRes . status ( 500 ) . end ( ) ;
48- }
49- } ;
27+ export const defaultResponseEncoder : ResponseEncoder =
28+ ( route , serviceFnResponse ) => ( _req , res ) => {
29+ const { type, payload } = serviceFnResponse ;
30+ const status = typeof type === 'number' ? type : ( KeyToHttpStatus as any ) [ type ] ;
31+ if ( status === undefined ) {
32+ console . warn ( 'Unknown status code returned' ) ;
33+ res . status ( 500 ) . end ( ) ;
34+ return ;
35+ }
36+ const responseCodec = route . response [ status ] ;
37+ try {
38+ res . status ( status ) . json ( responseCodec ! . encode ( payload ) ) . end ( ) ;
39+ } catch {
40+ console . warn (
41+ "Unable to encode route's return value, did you return the expected type?" ,
42+ ) ;
43+ res . status ( 500 ) . end ( ) ;
44+ }
45+ } ;
0 commit comments