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+
15# 1.1.19 - 7 Oct 2024
26Bug fix:
37- 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'
22
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 ( )
98 }
109 } )
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 ( )
1912 } )
2013
21- export default optionalUserMiddleware
14+ console . log ( app . routes [ 0 ] . hooks )
Original file line number Diff line number Diff line change 11{
22 "name" : " elysia" ,
33 "description" : " Ergonomic Framework for Human" ,
4- "version" : " 1.1.19 " ,
4+ "version" : " 1.1.20 " ,
55 "author" : {
66 "name" : " saltyAom" ,
77 "url" : " https://github.com/SaltyAom" ,
Original file line number Diff line number Diff line change @@ -165,6 +165,8 @@ export const mergeResponse = (
165165
166166 if ( isRecordNumber ( a ) && isRecordNumber ( b ) )
167167 return { ...( a as RecordNumber ) , ...( b as RecordNumber ) }
168+ else if ( a && ! isRecordNumber ( a ) && isRecordNumber ( b ) )
169+ return { 200 : a , ...( b as RecordNumber ) }
168170
169171 return b ?? a
170172}
Original file line number Diff line number Diff line change @@ -401,4 +401,23 @@ describe('guard', () => {
401401 expect ( called ) . toBe ( 3 )
402402 expect ( response ) . toEqual ( [ 422 , 200 ] )
403403 } )
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+ } )
404423} )
You can’t perform that action at this time.
0 commit comments