@@ -21,27 +21,35 @@ function _setSearchString(query = {}) {
21
21
return search . toString ( ) ;
22
22
}
23
23
24
- async function _fetch ( path , fetchOpts = { } , apiOpts = { handleError : true } ) {
25
- const fetchOptions = { ...defaultOptions , ...fetchOpts } ;
24
+ async function _fetch (
25
+ path ,
26
+ fetchOpts = { } ,
27
+ apiOpts = {
28
+ handleError : true ,
29
+ } ,
30
+ ) {
31
+ const fetchOptions = {
32
+ ...defaultOptions ,
33
+ ...fetchOpts ,
34
+ } ;
26
35
if ( ! [ 'GET' , 'HEAD' , 'OPTIONS' ] . includes ( fetchOptions . method ) ) {
27
36
fetchOptions . headers [ 'x-csrf-token' ] = session . csrfToken ( ) ;
28
37
}
29
38
30
- let request = fetch ( `${ apiUrl } /admin${ path } ` , fetchOptions )
31
- . then ( async ( r ) => {
32
- if ( r . ok ) return r . json ( ) ;
33
- if ( r . status === 401 ) {
34
- authLogout ( ) ;
35
- return null ;
36
- }
37
- if ( r . status === 422 ) {
38
- const json = await r . json ( ) ;
39
- const error = new Error ( json . message || r . statusText ) ;
40
- error . errors = json . errors ;
41
- throw error ;
42
- }
43
- throw new Error ( r . statusText ) ;
44
- } ) ;
39
+ let request = fetch ( `${ apiUrl } /admin${ path } ` , fetchOptions ) . then ( async ( r ) => {
40
+ if ( r . ok ) return r . json ( ) ;
41
+ if ( r . status === 401 ) {
42
+ authLogout ( ) ;
43
+ return null ;
44
+ }
45
+ if ( r . status === 422 ) {
46
+ const json = await r . json ( ) ;
47
+ const error = new Error ( json . message || r . statusText ) ;
48
+ error . errors = json . errors ;
49
+ throw error ;
50
+ }
51
+ throw new Error ( r . statusText ) ;
52
+ } ) ;
45
53
46
54
if ( apiOpts . handleError ) {
47
55
request = request . catch ( ( e ) => {
@@ -55,24 +63,25 @@ async function _fetch(path, fetchOpts = {}, apiOpts = { handleError: true }) {
55
63
}
56
64
57
65
async function _fetchAttachedFile ( path ) {
58
- const fetchOptions = { ...defaultOptions } ;
66
+ const fetchOptions = {
67
+ ...defaultOptions ,
68
+ } ;
59
69
fetchOptions . headers [ 'x-csrf-token' ] = session . csrfToken ( ) ;
60
70
61
- let request = fetch ( `${ apiUrl } /admin${ path } ` , fetchOptions )
62
- . then ( async ( r ) => {
63
- if ( r . ok ) return r . text ( ) ;
64
- if ( r . status === 401 ) {
65
- authLogout ( ) ;
66
- return null ;
67
- }
68
- if ( r . status === 422 ) {
69
- const json = await r . json ( ) ;
70
- const error = new Error ( json . message || r . statusText ) ;
71
- error . errors = json . errors ;
72
- throw error ;
73
- }
74
- throw new Error ( r . statusText ) ;
75
- } ) ;
71
+ let request = fetch ( `${ apiUrl } /admin${ path } ` , fetchOptions ) . then ( async ( r ) => {
72
+ if ( r . ok ) return r . text ( ) ;
73
+ if ( r . status === 401 ) {
74
+ authLogout ( ) ;
75
+ return null ;
76
+ }
77
+ if ( r . status === 422 ) {
78
+ const json = await r . json ( ) ;
79
+ const error = new Error ( json . message || r . statusText ) ;
80
+ error . errors = json . errors ;
81
+ throw error ;
82
+ }
83
+ throw new Error ( r . statusText ) ;
84
+ } ) ;
76
85
77
86
request = request . catch ( ( e ) => {
78
87
notification . setError ( `API request failed: ${ e . message } ` ) ;
@@ -84,7 +93,10 @@ async function _fetchAttachedFile(path) {
84
93
}
85
94
86
95
function destroy ( path , body ) {
87
- return _fetch ( path , { method : 'DELETE' , body : JSON . stringify ( body ) } ) ;
96
+ return _fetch ( path , {
97
+ method : 'DELETE' ,
98
+ body : JSON . stringify ( body ) ,
99
+ } ) ;
88
100
}
89
101
90
102
function get ( path , query ) {
@@ -101,11 +113,21 @@ function getAttachedFile(path) {
101
113
}
102
114
103
115
function post ( path , body = { } , opts = { } ) {
104
- return _fetch ( path , { method : 'POST' , body : JSON . stringify ( body ) } , opts ) ;
116
+ return _fetch (
117
+ path ,
118
+ {
119
+ method : 'POST' ,
120
+ body : JSON . stringify ( body ) ,
121
+ } ,
122
+ opts ,
123
+ ) ;
105
124
}
106
125
107
126
function put ( path , body ) {
108
- return _fetch ( path , { method : 'PUT' , body : JSON . stringify ( body ) } ) ;
127
+ return _fetch ( path , {
128
+ method : 'PUT' ,
129
+ body : JSON . stringify ( body ) ,
130
+ } ) ;
109
131
}
110
132
111
133
async function destroySite ( id ) {
@@ -117,7 +139,9 @@ async function fetchMe() {
117
139
}
118
140
119
141
function fetchBuildLogEventSource ( id , onMessage ) {
120
- const es = new EventSource ( `${ apiUrl } /admin/builds/${ id } /log` , { withCredentials : true } ) ;
142
+ const es = new EventSource ( `${ apiUrl } /admin/builds/${ id } /log` , {
143
+ withCredentials : true ,
144
+ } ) ;
121
145
es . addEventListener ( 'message' , onMessage ) ;
122
146
es . addEventListener ( 'error' , ( error ) => {
123
147
console . error ( 'EventSource failed:' , error ) ;
0 commit comments