Skip to content

Commit

Permalink
Fix error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
rxdn committed Jul 19, 2024
1 parent 3c44350 commit bd57603
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/s3client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ func (c *S3Client) GetTicket(ctx context.Context, guildId uint64, ticketId int)

object, err := c.client.GetObject(ctx, c.bucketName, key, minio.GetObjectOptions{})
if err != nil {
var resp minio.ErrorResponse
if errors.As(err, &resp) {
if resp.Code == "NoSuchKey" {
return nil, ErrTicketNotFound
}
if isNotFoundErr(err) {
return nil, ErrTicketNotFound
} else {
return nil, err
}

return nil, err
}

defer object.Close()

if _, err := object.Stat(); err != nil {
if isNotFoundErr(err) {
return nil, ErrTicketNotFound
} else {
return nil, err
}
}

var buff bytes.Buffer
if _, err := buff.ReadFrom(object); err != nil {
return nil, err
Expand Down Expand Up @@ -79,3 +84,8 @@ func (c *S3Client) GetAllKeysForGuild(ctx context.Context, guildId uint64) ([]st

return keys, nil
}

func isNotFoundErr(err error) bool {
var resp minio.ErrorResponse
return errors.As(err, &resp) && resp.Code == "NoSuchKey"
}

0 comments on commit bd57603

Please sign in to comment.