Skip to content

Commit

Permalink
Merge pull request #762 from shivang007/sqs-batch-failure-error-stack
Browse files Browse the repository at this point in the history
Sqs batch failure error stack
  • Loading branch information
willfarrell authored Jan 4, 2022
2 parents 313315b + 60c9453 commit b9b8ee1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/sqs-partial-batch-failure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const sqsPartialBatchFailureMiddleware = (opts = {}) => {
await deleteSqsMessages(fulfilledRecords)

const errorMessage = getErrorMessage(rejectedReasons)
throw new Error(errorMessage)
const error = new Error(errorMessage)
error.originalErrors = rejectedReasons
throw error
}

return {
Expand All @@ -86,10 +88,11 @@ const sqsPartialBatchFailureMiddleware = (opts = {}) => {
}

const getRejectedReasons = (response) => {
const rejected = response.filter((r) => r.status === 'rejected')
const rejectedReasons = rejected.map((r) => r.reason?.message)
const filteredRes = response
.filter((r) => r.status === 'rejected')
.map((r) => r.reason)

return rejectedReasons
return filteredRes
}

const getFulfilledRecords = (records, response) => {
Expand All @@ -108,6 +111,6 @@ const getEntries = (fulfilledRecords) => {
}

const getErrorMessage = (rejectedReasons) => {
return rejectedReasons.join('\n')
return rejectedReasons.map(error => error.message).join('\n')
}
module.exports = sqsPartialBatchFailureMiddleware

0 comments on commit b9b8ee1

Please sign in to comment.