@@ -135,7 +135,7 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
135
135
// we should verify the ACTIONS_RUNTIME_TOKEN
136
136
authHeader := req .Header .Get ("Authorization" )
137
137
if len (authHeader ) == 0 || ! strings .HasPrefix (authHeader , "Bearer " ) {
138
- ctx .Error (http .StatusUnauthorized , "Bad authorization header" )
138
+ ctx .HTTPError (http .StatusUnauthorized , "Bad authorization header" )
139
139
return
140
140
}
141
141
@@ -147,12 +147,12 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
147
147
task , err = actions .GetTaskByID (req .Context (), tID )
148
148
if err != nil {
149
149
log .Error ("Error runner api getting task by ID: %v" , err )
150
- ctx .Error (http .StatusInternalServerError , "Error runner api getting task by ID" )
150
+ ctx .HTTPError (http .StatusInternalServerError , "Error runner api getting task by ID" )
151
151
return
152
152
}
153
153
if task .Status != actions .StatusRunning {
154
154
log .Error ("Error runner api getting task: task is not running" )
155
- ctx .Error (http .StatusInternalServerError , "Error runner api getting task: task is not running" )
155
+ ctx .HTTPError (http .StatusInternalServerError , "Error runner api getting task: task is not running" )
156
156
return
157
157
}
158
158
} else {
@@ -162,14 +162,14 @@ func ArtifactContexter() func(next http.Handler) http.Handler {
162
162
task , err = actions .GetRunningTaskByToken (req .Context (), authToken )
163
163
if err != nil {
164
164
log .Error ("Error runner api getting task: %v" , err )
165
- ctx .Error (http .StatusInternalServerError , "Error runner api getting task" )
165
+ ctx .HTTPError (http .StatusInternalServerError , "Error runner api getting task" )
166
166
return
167
167
}
168
168
}
169
169
170
170
if err := task .LoadJob (req .Context ()); err != nil {
171
171
log .Error ("Error runner api getting job: %v" , err )
172
- ctx .Error (http .StatusInternalServerError , "Error runner api getting job" )
172
+ ctx .HTTPError (http .StatusInternalServerError , "Error runner api getting job" )
173
173
return
174
174
}
175
175
@@ -211,7 +211,7 @@ func (ar artifactRoutes) getUploadArtifactURL(ctx *ArtifactContext) {
211
211
var req getUploadArtifactRequest
212
212
if err := json .NewDecoder (ctx .Req .Body ).Decode (& req ); err != nil {
213
213
log .Error ("Error decode request body: %v" , err )
214
- ctx .Error (http .StatusInternalServerError , "Error decode request body" )
214
+ ctx .HTTPError (http .StatusInternalServerError , "Error decode request body" )
215
215
return
216
216
}
217
217
@@ -250,7 +250,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
250
250
expiredDays , err = strconv .ParseInt (queryRetentionDays , 10 , 64 )
251
251
if err != nil {
252
252
log .Error ("Error parse retention days: %v" , err )
253
- ctx .Error (http .StatusBadRequest , "Error parse retention days" )
253
+ ctx .HTTPError (http .StatusBadRequest , "Error parse retention days" )
254
254
return
255
255
}
256
256
}
@@ -261,7 +261,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
261
261
artifact , err := actions .CreateArtifact (ctx , task , artifactName , artifactPath , expiredDays )
262
262
if err != nil {
263
263
log .Error ("Error create or get artifact: %v" , err )
264
- ctx .Error (http .StatusInternalServerError , "Error create or get artifact" )
264
+ ctx .HTTPError (http .StatusInternalServerError , "Error create or get artifact" )
265
265
return
266
266
}
267
267
@@ -271,7 +271,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
271
271
chunksTotalSize , err := saveUploadChunk (ar .fs , ctx , artifact , contentLength , runID )
272
272
if err != nil {
273
273
log .Error ("Error save upload chunk: %v" , err )
274
- ctx .Error (http .StatusInternalServerError , "Error save upload chunk" )
274
+ ctx .HTTPError (http .StatusInternalServerError , "Error save upload chunk" )
275
275
return
276
276
}
277
277
@@ -285,7 +285,7 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
285
285
artifact .ContentEncoding = ctx .Req .Header .Get ("Content-Encoding" )
286
286
if err := actions .UpdateArtifactByID (ctx , artifact .ID , artifact ); err != nil {
287
287
log .Error ("Error update artifact: %v" , err )
288
- ctx .Error (http .StatusInternalServerError , "Error update artifact" )
288
+ ctx .HTTPError (http .StatusInternalServerError , "Error update artifact" )
289
289
return
290
290
}
291
291
log .Debug ("[artifact] update artifact size, artifact_id: %d, size: %d, compressed size: %d" ,
@@ -307,12 +307,12 @@ func (ar artifactRoutes) comfirmUploadArtifact(ctx *ArtifactContext) {
307
307
artifactName := ctx .Req .URL .Query ().Get ("artifactName" )
308
308
if artifactName == "" {
309
309
log .Error ("Error artifact name is empty" )
310
- ctx .Error (http .StatusBadRequest , "Error artifact name is empty" )
310
+ ctx .HTTPError (http .StatusBadRequest , "Error artifact name is empty" )
311
311
return
312
312
}
313
313
if err := mergeChunksForRun (ctx , ar .fs , runID , artifactName ); err != nil {
314
314
log .Error ("Error merge chunks: %v" , err )
315
- ctx .Error (http .StatusInternalServerError , "Error merge chunks" )
315
+ ctx .HTTPError (http .StatusInternalServerError , "Error merge chunks" )
316
316
return
317
317
}
318
318
ctx .JSON (http .StatusOK , map [string ]string {
@@ -340,12 +340,12 @@ func (ar artifactRoutes) listArtifacts(ctx *ArtifactContext) {
340
340
artifacts , err := db .Find [actions.ActionArtifact ](ctx , actions.FindArtifactsOptions {RunID : runID })
341
341
if err != nil {
342
342
log .Error ("Error getting artifacts: %v" , err )
343
- ctx .Error (http .StatusInternalServerError , err .Error ())
343
+ ctx .HTTPError (http .StatusInternalServerError , err .Error ())
344
344
return
345
345
}
346
346
if len (artifacts ) == 0 {
347
347
log .Debug ("[artifact] handleListArtifacts, no artifacts" )
348
- ctx .Error (http .StatusNotFound )
348
+ ctx .HTTPError (http .StatusNotFound )
349
349
return
350
350
}
351
351
@@ -405,18 +405,18 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
405
405
})
406
406
if err != nil {
407
407
log .Error ("Error getting artifacts: %v" , err )
408
- ctx .Error (http .StatusInternalServerError , err .Error ())
408
+ ctx .HTTPError (http .StatusInternalServerError , err .Error ())
409
409
return
410
410
}
411
411
if len (artifacts ) == 0 {
412
412
log .Debug ("[artifact] getDownloadArtifactURL, no artifacts" )
413
- ctx .Error (http .StatusNotFound )
413
+ ctx .HTTPError (http .StatusNotFound )
414
414
return
415
415
}
416
416
417
417
if itemPath != artifacts [0 ].ArtifactName {
418
418
log .Error ("Error dismatch artifact name, itemPath: %v, artifact: %v" , itemPath , artifacts [0 ].ArtifactName )
419
- ctx .Error (http .StatusBadRequest , "Error dismatch artifact name" )
419
+ ctx .HTTPError (http .StatusBadRequest , "Error dismatch artifact name" )
420
420
return
421
421
}
422
422
@@ -460,24 +460,24 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) {
460
460
artifact , exist , err := db .GetByID [actions.ActionArtifact ](ctx , artifactID )
461
461
if err != nil {
462
462
log .Error ("Error getting artifact: %v" , err )
463
- ctx .Error (http .StatusInternalServerError , err .Error ())
463
+ ctx .HTTPError (http .StatusInternalServerError , err .Error ())
464
464
return
465
465
}
466
466
if ! exist {
467
467
log .Error ("artifact with ID %d does not exist" , artifactID )
468
- ctx .Error (http .StatusNotFound , fmt .Sprintf ("artifact with ID %d does not exist" , artifactID ))
468
+ ctx .HTTPError (http .StatusNotFound , fmt .Sprintf ("artifact with ID %d does not exist" , artifactID ))
469
469
return
470
470
}
471
471
if artifact .RunID != runID {
472
472
log .Error ("Error mismatch runID and artifactID, task: %v, artifact: %v" , runID , artifactID )
473
- ctx .Error (http .StatusBadRequest )
473
+ ctx .HTTPError (http .StatusBadRequest )
474
474
return
475
475
}
476
476
477
477
fd , err := ar .fs .Open (artifact .StoragePath )
478
478
if err != nil {
479
479
log .Error ("Error opening file: %v" , err )
480
- ctx .Error (http .StatusInternalServerError , err .Error ())
480
+ ctx .HTTPError (http .StatusInternalServerError , err .Error ())
481
481
return
482
482
}
483
483
defer fd .Close ()
0 commit comments