Skip to content

Commit

Permalink
fix: handle serialization of error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jta committed Oct 3, 2023
1 parent 55f07ac commit ade7be6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions handlers/forwarder/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ func (h *Handler) Handle(ctx context.Context, request events.SQSEvent) (response
m := &SQSMessage{SQSMessage: record}
for _, sourceURI := range m.GetObjectCreated() {
copyInput := GetCopyObjectInput(sourceURI, h.DestinationURI)
if _, m.Error = h.S3Client.CopyObject(ctx, copyInput); m.Error != nil {
logger.Error(m.Error, "error copying file")
if _, cerr := h.S3Client.CopyObject(ctx, copyInput); cerr != nil {
logger.Error(cerr, "error copying file")
m.ErrorMessage = cerr.Error()
response.BatchItemFailures = append(response.BatchItemFailures, events.SQSBatchItemFailure{
ItemIdentifier: record.MessageId,
})
Expand Down
18 changes: 9 additions & 9 deletions handlers/forwarder/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import (

type SQSMessage struct {
events.SQSMessage
Error error `json:"error,omitempty"`
}

func getS3URI(bucketName string, objectKey string) *url.URL {
s := fmt.Sprintf("s3://%s/%s", bucketName, objectKey)
if u, err := url.ParseRequestURI(s); err == nil {
return u
}
return nil
ErrorMessage string `json:"error,omitempty"`
}

func (m *SQSMessage) GetObjectCreated() (uris []*url.URL) {
Expand All @@ -38,6 +30,14 @@ func (m *SQSMessage) GetObjectCreated() (uris []*url.URL) {
return
}

func getS3URI(bucketName string, objectKey string) *url.URL {
s := fmt.Sprintf("s3://%s/%s", bucketName, objectKey)
if u, err := url.ParseRequestURI(s); err == nil {
return u
}
return nil
}

func processS3Event(message []byte) (uris []*url.URL) {
var s3records events.S3Event
err := json.Unmarshal(message, &s3records)
Expand Down

0 comments on commit ade7be6

Please sign in to comment.