Skip to content

Commit

Permalink
Merge pull request #60 from commercetools/serialize-parse-error
Browse files Browse the repository at this point in the history
Log JSON received from the CTP
  • Loading branch information
LEQADA authored May 3, 2019
2 parents 88086ec + 39dede3 commit 28599d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"bluebird": "^3.5.3",
"bunyan": "^1.8.12",
"lodash": "^4.17.11",
"node-fetch": "^2.3.0"
"node-fetch": "^2.3.0",
"serialize-error": "^3.0.0"
}
}
11 changes: 9 additions & 2 deletions extension/src/api/payment/payment.controller.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const serializeError = require('serialize-error')
const httpUtils = require('../../utils')
const creditCardHandler = require('../../paymentHandler/creditCard/credit-card.handler')
const paypalHandler = require('../../paymentHandler/paypal/paypal.handler')
Expand Down Expand Up @@ -47,8 +48,14 @@ async function processRequest (request, response) {
}

async function _getPaymentObject (request) {
const requestBody = JSON.parse(await httpUtils.collectRequestData(request))
return requestBody.resource.obj
const body = await httpUtils.collectRequestData(request)
try {
const requestBody = JSON.parse(body)
return requestBody.resource.obj
} catch (err) {
throw new Error(`Error during parsing CTP request: '${body}'. Ending the process. `
+ `Error: ${JSON.stringify(serializeError(err))}`)
}
}

function _getPaymentHandler (paymentObject) {
Expand Down

0 comments on commit 28599d6

Please sign in to comment.