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)
| 321 | // HandleErrors TODO: Improve Error Handling |
| 322 | // HandleErrors handles errors and writes the appropriate response to the client. |
| 323 | func (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 | |
| 343 | func (h *handler) HandleError(ctx context.Context, w http.ResponseWriter, err error) { |
| 344 | if nil != err { |
no test coverage detected