Commit fa8323a1a85d9501436a2dffd3a9fb2ff1858084
1 parent
c0b96d30e5
Exists in
master
Add xid and stringify report message if is not a string
Showing 3 changed files with 21 additions and 6 deletions Side-by-side Diff
gateway/pull.js
1 | 1 | const IS_DEBUG = process.env.KOMODO_SDK_DEBUG_PULL; |
2 | 2 | |
3 | 3 | const request = require('request'); |
4 | +const stringify = require('json-stringify-pretty-compact'); | |
4 | 5 | const logger = require('tektrans-logger'); |
5 | 6 | |
6 | 7 | const config = require('../config'); |
... | ... | @@ -288,7 +289,7 @@ function replaceRc(original_rc) { |
288 | 289 | return config.replace_rc[original_rc] || original_rc; |
289 | 290 | } |
290 | 291 | |
291 | -function report(data) { | |
292 | +function report(data, xid) { | |
292 | 293 | |
293 | 294 | let core_pull_report_url; |
294 | 295 | |
... | ... | @@ -328,7 +329,7 @@ function report(data) { |
328 | 329 | trx_id: trx_id, |
329 | 330 | rc: replaceRc(data.rc), |
330 | 331 | rc_from_handler: data.rc_from_handler, |
331 | - message: data.message, | |
332 | + message: typeof data.message === 'string' ? data.message : stringify(data.message), | |
332 | 333 | handler: config.handler_name, |
333 | 334 | sn: data.sn, |
334 | 335 | amount: data.amount, |
... | ... | @@ -342,20 +343,22 @@ function report(data) { |
342 | 343 | } |
343 | 344 | |
344 | 345 | if (!config.do_not_verbose_log_report) { |
345 | - logger.verbose('Report to CORE using HTTP POST'); | |
346 | + logger.verbose('Report to CORE using HTTP POST', { xid }); | |
346 | 347 | } |
347 | 348 | |
348 | 349 | request.post(options, function(error, response) { |
349 | 350 | if (error) { |
350 | - logger.warn('Error reporting to CORE', {error: error}); | |
351 | + logger.warn('Error reporting to CORE', { xid, error }); | |
351 | 352 | resendReport(data); |
352 | 353 | } |
353 | 354 | else if (response.statusCode != 200) { |
354 | - logger.warn('Error reporting to CORE, http response status is not 200', {requestOptions: options, http_response_status: response.statusCode}); | |
355 | + logger.warn('Error reporting to CORE, http response status is not 200', { | |
356 | + xid, requestOptions: options, http_response_status: response.statusCode, | |
357 | + }); | |
355 | 358 | resendReport(data); |
356 | 359 | } |
357 | 360 | else if (!config.do_not_verbose_log_report) { |
358 | - logger.verbose('Report has been sent to CORE', {requestOptions: options}); | |
361 | + logger.verbose('Report has been sent to CORE', { xid, requestOptions: options }); | |
359 | 362 | } |
360 | 363 | }); |
361 | 364 | } |
package-lock.json
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | "express-session": "^1.15.6", |
19 | 19 | "fs-copy-file": "^2.1.2", |
20 | 20 | "json-query": "^2.2.2", |
21 | + "json-stringify-pretty-compact": "^3.0.0", | |
21 | 22 | "lru-cache": "^4.1.1", |
22 | 23 | "macaddress": "^0.2.9", |
23 | 24 | "moment": "^2.24.0", |
... | ... | @@ -1656,6 +1657,11 @@ |
1656 | 1657 | "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", |
1657 | 1658 | "dev": true |
1658 | 1659 | }, |
1660 | + "node_modules/json-stringify-pretty-compact": { | |
1661 | + "version": "3.0.0", | |
1662 | + "resolved": "https://registry.npmjs.org/json-stringify-pretty-compact/-/json-stringify-pretty-compact-3.0.0.tgz", | |
1663 | + "integrity": "sha512-Rc2suX5meI0S3bfdZuA7JMFBGkJ875ApfVyq2WHELjBiiG22My/l7/8zPpH/CfFVQHuVLd8NLR0nv6vi0BYYKA==" | |
1664 | + }, | |
1659 | 1665 | "node_modules/json-stringify-safe": { |
1660 | 1666 | "version": "5.0.1", |
1661 | 1667 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", |
... | ... | @@ -4212,6 +4218,11 @@ |
4212 | 4218 | "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", |
4213 | 4219 | "dev": true |
4214 | 4220 | }, |
4221 | + "json-stringify-pretty-compact": { | |
4222 | + "version": "3.0.0", | |
4223 | + "resolved": "https://registry.npmjs.org/json-stringify-pretty-compact/-/json-stringify-pretty-compact-3.0.0.tgz", | |
4224 | + "integrity": "sha512-Rc2suX5meI0S3bfdZuA7JMFBGkJ875ApfVyq2WHELjBiiG22My/l7/8zPpH/CfFVQHuVLd8NLR0nv6vi0BYYKA==" | |
4225 | + }, | |
4215 | 4226 | "json-stringify-safe": { |
4216 | 4227 | "version": "5.0.1", |
4217 | 4228 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", |
package.json