File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed
Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,13 @@ export class FetchRequest {
1010
1111 async perform ( ) {
1212 const response = new FetchResponse ( await window . fetch ( this . url , this . fetchOptions ) )
13+
1314 if ( response . unauthenticated && response . authenticationURL ) {
1415 return Promise . reject ( window . location . href = response . authenticationURL )
15- } else {
16- if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
17- return response
1816 }
17+
18+ if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
19+ return response
1920 }
2021
2122 get fetchOptions ( ) {
@@ -52,9 +53,9 @@ export class FetchRequest {
5253 return undefined
5354 } else if ( this . body instanceof window . File ) {
5455 return this . body . type
55- } else {
56- return 'application/json'
5756 }
57+
58+ return 'application/json'
5859 }
5960
6061 get accept ( ) {
@@ -89,12 +90,14 @@ export class FetchRequest {
8990
9091function compact ( object ) {
9192 const result = { }
93+
9294 for ( const key in object ) {
9395 const value = object [ key ]
9496 if ( value !== undefined ) {
9597 result [ key ] = value
9698 }
9799 }
100+
98101 return result
99102}
100103
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ export class FetchResponse {
2121
2222 get contentType ( ) {
2323 const contentType = this . response . headers . get ( 'Content-Type' ) || ''
24+
2425 return contentType . replace ( / ; .* $ / , '' )
2526 }
2627
@@ -31,17 +32,17 @@ export class FetchResponse {
3132 get html ( ) {
3233 if ( this . contentType . match ( / ^ ( a p p l i c a t i o n | t e x t ) \/ ( h t m l | x h t m l \+ x m l ) $ / ) ) {
3334 return this . response . text ( )
34- } else {
35- return Promise . reject ( new Error ( `Expected an HTML response but got "${ this . contentType } " instead` ) )
3635 }
36+
37+ return Promise . reject ( new Error ( `Expected an HTML response but got "${ this . contentType } " instead` ) )
3738 }
3839
3940 get json ( ) {
4041 if ( this . contentType . match ( / ^ a p p l i c a t i o n \/ j s o n / ) ) {
4142 return this . response . json ( )
42- } else {
43- return Promise . reject ( new Error ( `Expected a JSON response but got "${ this . contentType } " instead` ) )
4443 }
44+
45+ return Promise . reject ( new Error ( `Expected a JSON response but got "${ this . contentType } " instead` ) )
4546 }
4647
4748 get text ( ) {
@@ -59,8 +60,8 @@ export class FetchResponse {
5960 } else {
6061 console . warn ( 'You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js' )
6162 }
62- } else {
63- return Promise . reject ( new Error ( `Expected a Turbo Stream response but got "${ this . contentType } " instead` ) )
6463 }
64+
65+ return Promise . reject ( new Error ( `Expected a Turbo Stream response but got "${ this . contentType } " instead` ) )
6566 }
6667}
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ export function getCookie (name) {
55
66 if ( cookie ) {
77 const value = cookie . split ( '=' ) . slice ( 1 ) . join ( '=' )
8- return value ? decodeURIComponent ( value ) : undefined
8+
9+ if ( value ) {
10+ return decodeURIComponent ( value )
11+ }
912 }
1013}
You can’t perform that action at this time.
0 commit comments