Skip to content

Commit

Permalink
fix: fix error handling in case of errors from http endpoint when fet…
Browse files Browse the repository at this point in the history
…ching metadata sources
  • Loading branch information
anjaliagg9791 committed Aug 26, 2024
1 parent be2d47c commit 9e69a0f
Show file tree
Hide file tree
Showing 2 changed files with 396 additions and 10 deletions.
11 changes: 7 additions & 4 deletions core/appeal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (s *Service) Create(ctx context.Context, appeals []*domain.Appeal, opts ...
if err := s.addCreatorDetails(ctx, appeal, policy); err != nil {
return fmt.Errorf("getting creator details: %w", err)
}

if err := s.populateAppealMetadata(ctx, appeal, policy); err != nil {
return fmt.Errorf("getting appeal metadata: %w", err)
}
Expand Down Expand Up @@ -1573,9 +1573,12 @@ func (s *Service) populateAppealMetadata(ctx context.Context, a *domain.Appeal,
}

res, err := metadataCl.MakeRequest(egctx)
if err != nil || (res.StatusCode < 200 && res.StatusCode > 300) {
if !cfg.AllowFailed {
return fmt.Errorf("error fetching resource: %w", err)

if !cfg.AllowFailed {
if err != nil {
return fmt.Errorf("error fetching metadata for key %s from url %s, method: %s, body: %s : %w", key, cfg.URL, cfg.Method, cfg.Body, err)
} else if res.StatusCode < 200 || res.StatusCode > 300 {
return fmt.Errorf("status 2xx not received for metadata key %s from url %s, method: %s, body: %s", key, cfg.URL, cfg.Method, cfg.Body)
}
}

Expand Down
Loading

0 comments on commit 9e69a0f

Please sign in to comment.