File tree 3 files changed +19
-12
lines changed
3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,13 @@ export class FetchRequest {
19
19
console . error ( error )
20
20
}
21
21
const response = new FetchResponse ( await window . fetch ( this . url , this . fetchOptions ) )
22
+
22
23
if ( response . unauthenticated && response . authenticationURL ) {
23
24
return Promise . reject ( window . location . href = response . authenticationURL )
24
- } else {
25
- if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
26
- return response
27
25
}
26
+
27
+ if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
28
+ return response
28
29
}
29
30
30
31
addHeader ( key , value ) {
@@ -67,9 +68,9 @@ export class FetchRequest {
67
68
return undefined
68
69
} else if ( this . body instanceof window . File ) {
69
70
return this . body . type
70
- } else {
71
- return 'application/json'
72
71
}
72
+
73
+ return 'application/json'
73
74
}
74
75
75
76
get accept ( ) {
@@ -104,12 +105,14 @@ export class FetchRequest {
104
105
105
106
function compact ( object ) {
106
107
const result = { }
108
+
107
109
for ( const key in object ) {
108
110
const value = object [ key ]
109
111
if ( value !== undefined ) {
110
112
result [ key ] = value
111
113
}
112
114
}
115
+
113
116
return result
114
117
}
115
118
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ export class FetchResponse {
21
21
22
22
get contentType ( ) {
23
23
const contentType = this . response . headers . get ( 'Content-Type' ) || ''
24
+
24
25
return contentType . replace ( / ; .* $ / , '' )
25
26
}
26
27
@@ -31,17 +32,17 @@ export class FetchResponse {
31
32
get html ( ) {
32
33
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 ) $ / ) ) {
33
34
return this . response . text ( )
34
- } else {
35
- return Promise . reject ( new Error ( `Expected an HTML response but got "${ this . contentType } " instead` ) )
36
35
}
36
+
37
+ return Promise . reject ( new Error ( `Expected an HTML response but got "${ this . contentType } " instead` ) )
37
38
}
38
39
39
40
get json ( ) {
40
41
if ( this . contentType . match ( / ^ a p p l i c a t i o n \/ j s o n / ) ) {
41
42
return this . response . json ( )
42
- } else {
43
- return Promise . reject ( new Error ( `Expected a JSON response but got "${ this . contentType } " instead` ) )
44
43
}
44
+
45
+ return Promise . reject ( new Error ( `Expected a JSON response but got "${ this . contentType } " instead` ) )
45
46
}
46
47
47
48
get text ( ) {
@@ -59,8 +60,8 @@ export class FetchResponse {
59
60
} else {
60
61
console . warn ( 'You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js' )
61
62
}
62
- } else {
63
- return Promise . reject ( new Error ( `Expected a Turbo Stream response but got "${ this . contentType } " instead` ) )
64
63
}
64
+
65
+ return Promise . reject ( new Error ( `Expected a Turbo Stream response but got "${ this . contentType } " instead` ) )
65
66
}
66
67
}
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ export function getCookie (name) {
5
5
6
6
if ( cookie ) {
7
7
const value = cookie . split ( '=' ) . slice ( 1 ) . join ( '=' )
8
- return value ? decodeURIComponent ( value ) : undefined
8
+
9
+ if ( value ) {
10
+ return decodeURIComponent ( value )
11
+ }
9
12
}
10
13
}
You can’t perform that action at this time.
0 commit comments