File tree Expand file tree Collapse file tree 5 files changed +35
-17
lines changed Expand file tree Collapse file tree 5 files changed +35
-17
lines changed Original file line number Diff line number Diff line change
1
+ # 1.1.20 - 10 Oct 2024
2
+ Bug fix:
3
+ - merge guard and not specified hook responses status
4
+
1
5
# 1.1.19 - 7 Oct 2024
2
6
Bug fix:
3
7
- unable to return ` error ` from derive/resolve
Original file line number Diff line number Diff line change 1
- import { Elysia } from '../src'
1
+ import { Elysia , t } from '../src'
2
2
3
- const optionalUserMiddleware = ( app : Elysia ) =>
4
- app . derive ( { as : 'scoped' } , async ( ) => {
5
- const user = { name : 'something' }
6
-
7
- return {
8
- user
3
+ const app = new Elysia ( )
4
+ . guard ( {
5
+ response : {
6
+ 400 : t . String ( ) ,
7
+ 500 : t . String ( )
9
8
}
10
9
} )
11
-
12
- export const isUserAuthenticated = ( app : Elysia ) =>
13
- app . derive ( ( { error } ) => {
14
- if ( true ) return error ( 'Unauthorized' )
15
-
16
- return {
17
- user : 'a'
18
- }
10
+ . get ( '/' , ( ) => '' , {
11
+ response : t . String ( )
19
12
} )
20
13
21
- export default optionalUserMiddleware
14
+ console . log ( app . routes [ 0 ] . hooks )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " elysia" ,
3
3
"description" : " Ergonomic Framework for Human" ,
4
- "version" : " 1.1.19 " ,
4
+ "version" : " 1.1.20 " ,
5
5
"author" : {
6
6
"name" : " saltyAom" ,
7
7
"url" : " https://github.com/SaltyAom" ,
Original file line number Diff line number Diff line change @@ -165,6 +165,8 @@ export const mergeResponse = (
165
165
166
166
if ( isRecordNumber ( a ) && isRecordNumber ( b ) )
167
167
return { ...( a as RecordNumber ) , ...( b as RecordNumber ) }
168
+ else if ( a && ! isRecordNumber ( a ) && isRecordNumber ( b ) )
169
+ return { 200 : a , ...( b as RecordNumber ) }
168
170
169
171
return b ?? a
170
172
}
Original file line number Diff line number Diff line change @@ -401,4 +401,23 @@ describe('guard', () => {
401
401
expect ( called ) . toBe ( 3 )
402
402
expect ( response ) . toEqual ( [ 422 , 200 ] )
403
403
} )
404
+
405
+ it ( 'handle merge guard and hook responses status' , ( ) => {
406
+ const app = new Elysia ( )
407
+ . guard ( {
408
+ response : {
409
+ 400 : t . String ( ) ,
410
+ 500 : t . String ( )
411
+ }
412
+ } )
413
+ . get ( '/' , ( ) => '' , {
414
+ response : t . String ( )
415
+ } )
416
+
417
+ expect ( Object . keys ( app . routes [ 0 ] . hooks . response ) ) . toEqual ( [
418
+ '200' ,
419
+ '400' ,
420
+ '500'
421
+ ] )
422
+ } )
404
423
} )
You can’t perform that action at this time.
0 commit comments