File tree 3 files changed +32
-13
lines changed
3 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ Improvement:
36
36
- support resolve macro on ws
37
37
- [ #1146 ] ( https://github.com/elysiajs/elysia/pull/1146 ) add support to return web API's File from handler
38
38
- [ #1165 ] ( https://github.com/elysiajs/elysia/pull/1165 ) skip non-numeric status codes in response schema validation
39
+ - [ #1177 ] ( https://github.com/elysiajs/elysia/issues/1177 ) cookie does not sign when an error is thrown
39
40
40
41
Bug fix:
41
42
- ` Response ` returned from ` onError ` is using octet stream
Original file line number Diff line number Diff line change 1
1
import { Elysia , t } from '../src'
2
2
3
3
const app = new Elysia ( )
4
- . macro ( {
5
- a : {
6
- resolve : ( ) => ( {
7
- a : 'a'
4
+ . onError ( ( { code, error } ) => {
5
+ console . error ( '[error]' , error )
6
+ return { error : { code } }
7
+ } )
8
+ . get (
9
+ '/session' ,
10
+ ( { error, cookie : { sessionToken } } ) => {
11
+ const refreshed = ! ! sessionToken . value
12
+
13
+ sessionToken . set ( {
14
+ value : Math . random ( ) . toString ( 36 ) . substring ( 2 , 8 ) ,
15
+ maxAge : 1000 * 60 * 60 * 24 * 7
8
16
} )
17
+
18
+ if ( refreshed ) throw error ( 'Unauthorized' )
19
+
20
+ return sessionToken . value
21
+ } ,
22
+ {
23
+ cookie : t . Cookie (
24
+ { sessionToken : t . Optional ( t . String ( ) ) } ,
25
+ {
26
+ sign : [ 'sessionToken' ] ,
27
+ secrets : 'my-secret'
28
+ }
29
+ )
9
30
}
10
- } )
11
- . get ( '/a' , ( { a } ) => { } , {
12
- a : true ,
13
- beforeHandle : ( { query } ) => { }
14
- } )
15
- . ws ( '/' , {
16
- a : true ,
17
- message ( { data : { a } } ) { }
18
- } )
31
+ )
32
+ . listen ( 3000 )
33
+
34
+ console . log ( app . routes [ 0 ] . compile ( ) . toString ( ) )
Original file line number Diff line number Diff line change @@ -1873,6 +1873,8 @@ export const composeHandler = ({
1873
1873
`const set=c.set\n` +
1874
1874
`if(!set.status||set.status<300)set.status=error?.status||500\n`
1875
1875
1876
+ if ( hasCookie ) fnLiteral += encodeCookie ( )
1877
+
1876
1878
if ( hasTrace && hooks . trace )
1877
1879
for ( let i = 0 ; i < hooks . trace . length ; i ++ )
1878
1880
// There's a case where the error is thrown before any trace is called
You can’t perform that action at this time.
0 commit comments