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 @@ -10,12 +10,13 @@ export class FetchRequest {
10
10
11
11
async perform ( ) {
12
12
const response = new FetchResponse ( await window . fetch ( this . url , this . fetchOptions ) )
13
+
13
14
if ( response . unauthenticated && response . authenticationURL ) {
14
15
return Promise . reject ( window . location . href = response . authenticationURL )
15
- } else {
16
- if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
17
- return response
18
16
}
17
+
18
+ if ( response . ok && response . isTurboStream ) { response . renderTurboStream ( ) }
19
+ return response
19
20
}
20
21
21
22
get fetchOptions ( ) {
@@ -52,9 +53,9 @@ export class FetchRequest {
52
53
return undefined
53
54
} else if ( this . body instanceof window . File ) {
54
55
return this . body . type
55
- } else {
56
- return 'application/json'
57
56
}
57
+
58
+ return 'application/json'
58
59
}
59
60
60
61
get accept ( ) {
@@ -89,12 +90,14 @@ export class FetchRequest {
89
90
90
91
function compact ( object ) {
91
92
const result = { }
93
+
92
94
for ( const key in object ) {
93
95
const value = object [ key ]
94
96
if ( value !== undefined ) {
95
97
result [ key ] = value
96
98
}
97
99
}
100
+
98
101
return result
99
102
}
100
103
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