Skip to content

[SFMC] Mark specific error as retryable error #3100

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,71 @@ describe('Multistatus', () => {
errorreporter: 'DESTINATION'
})
})

it('should mark "Unable to save rows for data extension ID" error as retryable even if SFMC returns 400', async () => {
const errorResponse = {
status: 400,
message: 'Invalid keys for ID: HS1',
additionalErrors: [
{
errorcode: 10006,
message: 'Unable to save rows for data extension ID'
}
]
}

nock(requestUrl).post('').reply(400, errorResponse)

const events: SegmentEvent[] = [
createTestEvent({
type: 'track',
userId: 'harry-1',
properties: {
id: '1234567890',
keys: {
id: 'HS1' // Valid key
},
values: {
name: 'Harry Styles'
}
}
}),
createTestEvent({
type: 'track',
userId: 'harry-2',
properties: {
id: '1234567890',
keys: {
id: 'HS2' // Invalid key
},
values: {
name: 'Harry Potter'
}
}
})
]

const response = await testDestination.executeBatch('dataExtension', {
events,
settings,
mapping
})

expect(response[0]).toMatchObject({
status: 500,
errortype: 'INTERNAL_SERVER_ERROR',
errormessage: 'Unable to save rows for data extension ID',
errorreporter: 'DESTINATION'
})

expect(response[1]).toMatchObject({
status: 500,
errortype: 'INTERNAL_SERVER_ERROR',
errormessage: 'Unable to save rows for data extension ID',
errorreporter: 'DESTINATION'
})
})

it('should handle multistatus errors and set correct status code', async () => {
const errorResponse = {
status: 429,
Expand Down Expand Up @@ -467,6 +532,72 @@ describe('Multistatus', () => {
})
})

it('should mark "Unable to save rows for data extension ID" error as retryable even if SFMC returns 400', async () => {
const errorResponse = {
status: 400,
message: 'Invalid keys for ID: HS1',
additionalErrors: [
{
errorcode: 10006,
message: 'Unable to save rows for data extension ID'
}
]
}

nock(requestUrl).post('').reply(400, errorResponse)

const events: SegmentEvent[] = [
createTestEvent({
type: 'track',
userId: 'harry-1',
properties: {
id: '1234567890',
keys: {
contactKey: 'harry-1',
id: 'HS1'
},
values: {
name: 'Harry Styles'
}
}
}),
createTestEvent({
type: 'track',
userId: 'harry-2',
properties: {
id: '1234567890',
keys: {
contactKey: 'harry-2',
id: 'HS2'
},
values: {
name: 'Harry Potter'
}
}
})
]

const response = await testDestination.executeBatch('contactDataExtension', {
events,
settings,
mapping
})

expect(response[0]).toMatchObject({
status: 500,
errortype: 'INTERNAL_SERVER_ERROR',
errormessage: 'Unable to save rows for data extension ID',
errorreporter: 'DESTINATION'
})

expect(response[1]).toMatchObject({
status: 500,
errortype: 'INTERNAL_SERVER_ERROR',
errormessage: 'Unable to save rows for data extension ID',
errorreporter: 'DESTINATION'
})
})

it('should handle multistatus errors and set correct status code', async () => {
const errorResponse = {
status: 429,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,20 @@ export async function executeUpsertWithMultiStatus(
err.response.data.additionalErrors.length > 0 &&
err.response.data.additionalErrors

const retryableCodes = [10006]
const hasAnyRetryableError =
additionalError &&
additionalError.some(
(e) => retryableCodes.includes(e.errorcode) && e.message.includes('Unable to save rows for data extension ID')
)

let status = 500 // default status is 500
if (!hasAnyRetryableError && err?.response?.status) {
status = err.response.status
}
payloads.forEach((_, index) => {
multiStatusResponse.setErrorResponseAtIndex(index, {
status: err?.response?.status || 500,
status: status,
errormessage: additionalError ? additionalError[0].message : errData?.message || '',
sent: rows[index] as Object as JSONLikeObject,
/*
Expand Down
Loading