MCPcopy
hub / github.com/harness/harness / HandleErrors

Method HandleErrors

registry/app/api/handler/packages/handler.go:323–341  ·  view source on GitHub ↗

HandleErrors TODO: Improve Error Handling HandleErrors handles errors and writes the appropriate response to the client.

(ctx context.Context, errs errcode.Errors, w http.ResponseWriter)

Source from the content-addressed store, hash-verified

321// HandleErrors TODO: Improve Error Handling
322// HandleErrors handles errors and writes the appropriate response to the client.
323func (h *handler) HandleErrors(ctx context.Context, errs errcode.Errors, w http.ResponseWriter) {
324 if !commons.IsEmpty(errs) {
325 LogError(errs)
326 log.Ctx(ctx).Error().Errs("errs occurred during artifact operation: ", errs).Msgf("Error occurred")
327 err := errs[0]
328 var e *commons.Error
329 if errors.As(err, &e) {
330 code := e.Status
331 w.WriteHeader(code)
332 } else {
333 w.WriteHeader(http.StatusInternalServerError)
334 }
335 w.Header().Set("Content-Type", "application/json")
336 err = json.NewEncoder(w).Encode(errs)
337 if err != nil {
338 log.Ctx(ctx).Error().Err(err).Msgf("Error occurred during artifact error encoding")
339 }
340 }
341}
342
343func (h *handler) HandleError(ctx context.Context, w http.ResponseWriter, err error) {
344 if nil != err {

Callers 15

DownloadFileMethod · 0.95
GetPackageMetadataMethod · 0.95
SearchPackageMethod · 0.95
DownloadPackageFileMethod · 0.95
HeadPackageFileByNameMethod · 0.95
DownloadPackageFileMethod · 0.95
GetRepoDataMethod · 0.95
DownloadPackageFileMethod · 0.95
DownloadPackageIndexMethod · 0.95
DownloadPackageMethod · 0.95

Calls 9

MsgfMethod · 0.80
LogErrorFunction · 0.70
ErrorMethod · 0.65
SetMethod · 0.65
EncodeMethod · 0.65
ErrMethod · 0.65
IsEmptyMethod · 0.45
WriteHeaderMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected