Error response is in unreadable format

Sowmay
I have a web app based on NodeJS environment created using Kite JS official npm module.

Error is handled using API promises but the response I'm receiving is not in readable proper JSON format (as shown below):

{ StatusCodeError: 400 - "{\"status\": \"error\", \"message\": \"Missing access_token\", \"error_type\": \"InputException\"}"
at new StatusCodeError (/root/kite-fintrig/node_modules/request-promise-core/lib/errors.js:32:15)
at /root/kite-fintrig/node_modules/request-promise-core/lib/plumbing.js:97:41
at tryCatcher (/root/kite-fintrig/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/root/kite-fintrig/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/root/kite-fintrig/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (/root/kite-fintrig/node_modules/bluebird/js/release/promise.js:606:10)
at Async._drainQueue (/root/kite-fintrig/node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (/root/kite-fintrig/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/root/kite-fintrig/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
name: 'StatusCodeError',
statusCode: 400,
message: '400 - "{\\"status\\": \\"error\\", \\"message\\": \\"Missing access_token\\", \\"error_type\\": \\"InputException\\"}"',
error: '{"status": "error", "message": "Missing access_token", "error_type": "InputException"}',
options:
{ method: 'GET',
uri: 'https://api.kite.trade/user/margins/equity',
timeout: 7000,
transform: [Function: transform],
qs: { segment: 'equity', api_key: 'mwogkvjg1w37kbja' },
callback: [Function: RP$callback],
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false },
response:
{ status: 'error',
message: 'Missing access_token',
error_type: 'InputException' } }


Some errors are occurring in NodeJS env. How can I get a proper readable format of error?

Above error is stored in "e" variable below:

kiteConnectApiCall
.then(function(v) {
// On success
})
.catch(function(e) {
// On rejected
})

Am I lacking somewhere?
Tagged:
  • sujith
    Hi @Sowmay,
    Instead of printing e, try printing error.response.
    It should look somethinng like this,
    { status: 'error',
    message: 'Missing access_token',
    error_type: 'InputException' }
Sign In or Register to comment.