@@ -54,61 +54,53 @@ const handleResponseMeta = (c: Context, handler: Handler) => {
54
54
} ;
55
55
56
56
export const createHonoHandler = ( handler : Handler ) => {
57
- return async ( c : Context , next : Next ) => {
58
- try {
59
- const input = await getHonoInput ( c ) ;
57
+ return async ( c : Context ) => {
58
+ const input = await getHonoInput ( c ) ;
60
59
61
- if ( isWithMetaHandler ( handler ) ) {
62
- try {
63
- const response = handleResponseMeta ( c , handler ) ;
64
- if ( response ) {
65
- return response ;
66
- }
67
- if ( c . finalized ) return ;
60
+ if ( isWithMetaHandler ( handler ) ) {
61
+ try {
62
+ const response = handleResponseMeta ( c , handler ) ;
63
+ if ( response ) {
64
+ return response ;
65
+ }
66
+ if ( c . finalized ) return ;
68
67
69
- const result = await handler ( input ) ;
70
- if ( result instanceof Response ) {
71
- return result ;
72
- }
73
- return result && typeof result === 'object'
74
- ? c . json ( result )
75
- : c . body ( result ) ;
76
- } catch ( error ) {
77
- if ( error instanceof ValidationError ) {
78
- c . status ( ( error as any ) . status ) ;
68
+ const result = await handler ( input ) ;
69
+ if ( result instanceof Response ) {
70
+ return result ;
71
+ }
72
+ return result && typeof result === 'object'
73
+ ? c . json ( result )
74
+ : c . body ( result ) ;
75
+ } catch ( error ) {
76
+ if ( error instanceof ValidationError ) {
77
+ c . status ( ( error as any ) . status ) ;
79
78
80
- return c . json ( {
81
- message : error . message ,
82
- } ) ;
83
- }
84
- throw error ;
79
+ return c . json ( {
80
+ message : error . message ,
81
+ } ) ;
85
82
}
86
- } else {
87
- const routePath = c . req . routePath ;
88
- const paramNames = routePath . match ( / : \w + / g) ?. map ( s => s . slice ( 1 ) ) || [ ] ;
89
- const params = Object . fromEntries (
90
- paramNames . map ( name => [ name , input . params [ name ] ] ) ,
91
- ) ;
92
- const args = Object . values ( params ) . concat ( input ) ;
83
+ throw error ;
84
+ }
85
+ } else {
86
+ const routePath = c . req . routePath ;
87
+ const paramNames = routePath . match ( / : \w + / g) ?. map ( s => s . slice ( 1 ) ) || [ ] ;
88
+ const params = Object . fromEntries (
89
+ paramNames . map ( name => [ name , input . params [ name ] ] ) ,
90
+ ) ;
91
+ const args = Object . values ( params ) . concat ( input ) ;
93
92
94
- try {
95
- const body = await handler ( ...args ) ;
96
- if ( c . finalized ) {
97
- return await Promise . resolve ( ) ;
98
- }
93
+ const body = await handler ( ...args ) ;
94
+ if ( c . finalized ) {
95
+ return await Promise . resolve ( ) ;
96
+ }
99
97
100
- if ( typeof body !== 'undefined' ) {
101
- if ( body instanceof Response ) {
102
- return body ;
103
- }
104
- return c . json ( body ) ;
105
- }
106
- } catch {
107
- return next ( ) ;
98
+ if ( typeof body !== 'undefined' ) {
99
+ if ( body instanceof Response ) {
100
+ return body ;
108
101
}
102
+ return c . json ( body ) ;
109
103
}
110
- } catch ( error ) {
111
- next ( ) ;
112
104
}
113
105
} ;
114
106
} ;
0 commit comments