Skip to content

Commit

Permalink
Adds some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
StealWonders committed Feb 26, 2024
1 parent 192afaa commit 55595e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/graphql/resolvers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resolvers
import (
"context"
"fmt"
"github.com/getsentry/sentry-go"
"github.com/google/uuid"
ent "github.com/mensatt/backend/internal/database/ent"
"github.com/mensatt/backend/internal/database/ent/dish"
Expand Down Expand Up @@ -32,7 +33,7 @@ func (r *mutationResolver) rotateImage(uuid uuid.UUID, angle int) error {
defer response.Body.Close() // unhandled error

if response.StatusCode != 200 {
return fmt.Errorf("img-service: error rotating image")
return fmt.Errorf("img-service: error rotating image! Responded with status code: %d", response.StatusCode)
}

return nil
Expand All @@ -53,21 +54,25 @@ func (r *mutationResolver) submitImages(images []*models.ImageInput) []uuid.UUID

response, err := client.Do(request)
if err != nil {
sentry.CaptureException(fmt.Errorf("img-service: error submitting image: %v", err))
continue // ignore error and continue with the next image
}
defer response.Body.Close() // unhandled error

if response.StatusCode != 200 {
sentry.CaptureException(fmt.Errorf("img-service: error submitting image! Responded with status code: %d", response.StatusCode))
continue // ignore error and continue with the next image
}

body, err := io.ReadAll(response.Body)
if err != nil {
sentry.CaptureException(fmt.Errorf("img-service: error reading response body: %v", err))
continue // ignore error and continue with the next image
}

uuid, err := uuid.Parse(string(body))
if err != nil {
sentry.CaptureException(fmt.Errorf("img-service: error parsing response body as uuid: %v", err))
continue // ignore error and continue with the next image
}

Expand Down

0 comments on commit 55595e8

Please sign in to comment.