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 @@ -19,12 +19,13 @@ export class FetchRequest {
1919 console . error ( error )
2020 }
2121 const response = new FetchResponse ( await window . fetch ( this . url , this . fetchOptions ) )
22+
2223 if ( response . unauthenticated && response . authenticationURL ) {
2324 return Promise . reject ( window . location . href = response . authenticationURL )
24- } else {
25- if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
26- return response
2725 }
26+
27+ if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
28+ return response
2829 }
2930
3031 addHeader ( key , value ) {
@@ -67,9 +68,9 @@ export class FetchRequest {
6768 return undefined
6869 } else if ( this . body instanceof window . File ) {
6970 return this . body . type
70- } else {
71- return 'application/json'
7271 }
72+
73+ return 'application/json'
7374 }
7475
7576 get accept ( ) {
@@ -104,12 +105,14 @@ export class FetchRequest {
104105
105106function compact ( object ) {
106107 const result = { }
108+
107109 for ( const key in object ) {
108110 const value = object [ key ]
109111 if ( value !== undefined ) {
110112 result [ key ] = value
111113 }
112114 }
115+
113116 return result
114117}
115118
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