@@ -5,8 +5,7 @@ import {createApp} from 'vue';
5
5
import {toggleElem } from ' ../utils/dom.js' ;
6
6
import {getCurrentLocale } from ' ../utils.js' ;
7
7
import {renderAnsi } from ' ../render/ansi.js' ;
8
-
9
- const {csrfToken } = window .config ;
8
+ import {POST , isNetworkError } from ' ../modules/fetch.js' ;
10
9
11
10
const sfc = {
12
11
name: ' RepoActionView' ,
@@ -145,11 +144,11 @@ const sfc = {
145
144
},
146
145
// cancel a run
147
146
cancelRun () {
148
- this . fetchPost (` ${ this .run .link } /cancel` );
147
+ POST (` ${ this .run .link } /cancel` );
149
148
},
150
149
// approve a run
151
150
approveRun () {
152
- this . fetchPost (` ${ this .run .link } /approve` );
151
+ POST (` ${ this .run .link } /approve` );
153
152
},
154
153
155
154
createLogLine (line , startTime , stepIndex ) {
@@ -203,10 +202,9 @@ const sfc = {
203
202
// for example: make cursor=null means the first time to fetch logs, cursor=eof means no more logs, etc
204
203
return {step: idx, cursor: it .cursor , expanded: it .expanded };
205
204
});
206
- const resp = await this .fetchPost (
207
- ` ${ this .actionsURL } /runs/${ this .runIndex } /jobs/${ this .jobIndex } ` ,
208
- JSON .stringify ({logCursors}),
209
- );
205
+ const resp = await POST (` ${ this .actionsURL } /runs/${ this .runIndex } /jobs/${ this .jobIndex } ` , {
206
+ json: {logCursors},
207
+ });
210
208
return await resp .json ();
211
209
},
212
210
@@ -216,7 +214,7 @@ const sfc = {
216
214
this .loading = true ;
217
215
218
216
// refresh artifacts if upload-artifact step done
219
- const resp = await this . fetchPost (` ${ this .actionsURL } /runs/${ this .runIndex } /artifacts` );
217
+ const resp = await POST (` ${ this .actionsURL } /runs/${ this .runIndex } /artifacts` );
220
218
const artifacts = await resp .json ();
221
219
this .artifacts = artifacts[' artifacts' ] || [];
222
220
@@ -244,23 +242,16 @@ const sfc = {
244
242
clearInterval (this .intervalID );
245
243
this .intervalID = null ;
246
244
}
245
+ } catch (err) {
246
+ // avoid error while unloading page with fetch in progress
247
+ if (! isNetworkError (err .message )) {
248
+ throw err;
249
+ }
247
250
} finally {
248
251
this .loading = false ;
249
252
}
250
253
},
251
254
252
-
253
- fetchPost (url , body ) {
254
- return fetch (url, {
255
- method: ' POST' ,
256
- headers: {
257
- ' Content-Type' : ' application/json' ,
258
- ' X-Csrf-Token' : csrfToken,
259
- },
260
- body,
261
- });
262
- },
263
-
264
255
isDone (status ) {
265
256
return [' success' , ' skipped' , ' failure' , ' cancelled' ].includes (status);
266
257
},
0 commit comments