Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqs batch failure error stack #762

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion packages/sqs-partial-batch-failure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@middy/sqs-partial-batch-failure",
"version": "2.5.3",
"version": "2.5.4",
"description": "SQS partial batch failure middleware for the middy framework",
"type": "commonjs",
"engines": {
Expand Down