Skip to content

Commit

Permalink
Merge pull request #53 from commercetools/log-adyen-payload-in-case-o…
Browse files Browse the repository at this point in the history
…f-unexpected-error

#52 log the payload received from adyen in case of error
  • Loading branch information
LEQADA committed Apr 23, 2019
2 parents a6959d9 + 67ad217 commit 32cef94
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions notification/src/api/notification/notification.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ async function handleNotification (request, response) {
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ notificationResponse: '[accepted]' }))
} catch (e) {
logger.error(e, 'Unexpected exception occurred')
} catch (err) {
logger.error({ adyenRequestBody: `${body}`, err },
'Unexpected exception occurred.')
return httpUtils.sendResponse(response, 500)
}
}
Expand Down
2 changes: 1 addition & 1 deletion notification/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getFileConfig () {
let fileConfig = {}
try {
fileConfig = require(configPath) // eslint-disable-line
} catch (e) {
} catch (err) {
// config file was not provided
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async function ensureInterfaceInteractionCustomType (ctpClient) {
await ctpClient.create(ctpClient.builder.types, interfaceInteractionType)
logger.info('Successfully created an interfaceInteraction type')
}
} catch (e) {
logger.error(e, 'Error when creating interface interaction custom type, skipping...')
} catch (err) {
logger.error(err, 'Error when creating interface interaction custom type, skipping...')
}
}

Expand Down
14 changes: 7 additions & 7 deletions notification/src/handler/notification/notification.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ async function updatePaymentWithRepeater (payment, notification, ctpClient) {
logger.debug(`Payment with interfaceId ${currentPayment.interfaceId}`
+ 'was successfully updated')
break
} catch (e) {
if (e.body.statusCode !== 409)
} catch (err) {
if (err.body.statusCode !== 409)
throw new Error(`Unexpected error during updating a payment with ID: ${currentPayment.id}. Exiting. `
+ `Error: ${JSON.stringify(serializeError(e))}`)
+ `Error: ${JSON.stringify(serializeError(err))}`)
retryCount += 1
if (retryCount > maxRetry) {
retryMessage = 'Got a concurrent modification error'
+ ` when updating payment with id "${currentPayment.id}".`
+ ` Version tried "${currentVersion}",`
+ ` currentVersion: "${e.body.errors[0].currentVersion}".`
+ ` currentVersion: "${err.body.errors[0].currentVersion}".`
throw new Error(`${retryMessage} Won't retry again`
+ ` because of a reached limit ${maxRetry}`
+ ` max retries. Error: ${JSON.stringify(serializeError(e))}`)
+ ` max retries. Error: ${JSON.stringify(serializeError(err))}`)
}
/* eslint-disable-next-line no-await-in-loop */
currentPayment = await ctpClient.fetchById(ctpClient.builder.payments, currentPayment.id)
Expand Down Expand Up @@ -148,9 +148,9 @@ async function getPaymentByMerchantReference (merchantReference, ctpClient) {
try {
const result = await ctpClient.fetch(ctpClient.builder.payments.where(`interfaceId="${merchantReference}"`))
return _.get(result, 'body.results[0]', null)
} catch (e) {
} catch (err) {
throw Error(`Failed to fetch a payment with merchantReference: ${merchantReference}. `
+ `Error: ${JSON.stringify(serializeError(e))}`)
+ `Error: ${JSON.stringify(serializeError(err))}`)
}
}

Expand Down
4 changes: 2 additions & 2 deletions notification/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function setupServer (routes = defaultRoutes) {
if (route)
try {
await route(request, response)
} catch (e) {
logger.error(e, `Unexpected error when processing URL ${JSON.stringify(parts)}`)
} catch (err) {
logger.error(err, `Unexpected error when processing URL ${JSON.stringify(parts)}`)
utils.sendResponse(response, 500)
}
else
Expand Down
3 changes: 2 additions & 1 deletion notification/src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function getLogger () {
obj = bunyan.createLogger({
name: NOTIFICATION_MODULE_NAME,
stream: process.stdout,
level: logLevel || bunyan.INFO
level: logLevel || bunyan.INFO,
serializers: bunyan.stdSerializers
})
}
return obj
Expand Down

0 comments on commit 32cef94

Please sign in to comment.