Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Property message in Error response body cannot be accessed. #2420

Open
razik29 opened this issue Aug 17, 2017 · 0 comments
Open

Property message in Error response body cannot be accessed. #2420

razik29 opened this issue Aug 17, 2017 · 0 comments

Comments

@razik29
Copy link

razik29 commented Aug 17, 2017

Description

Using node I make a typical API POST request for which I have a .catch block with response variable say err. On error, the response body is returned as such (as seen from the Hyperledger Composer REST app)

{
  "error": {
    "statusCode": 500,
    "name": "Error",
    "message": "error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)",
    "stack": "Error: error trying invoke chaincode. Error: chaincode error (status: 500, message: Error: Payment needs to be of positive value)\n    at _initializeChannel.then.then.then.then.catch (/home/ubuntu/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:839:34)"
  }
}

My Issue

I am simply trying to fetch the message property from the above response and send it to the UI. But weirdly err.message does not give me the value I see inside message but returns the entire response body(same with err.stack).

So basically -- err, err.message and err.stack returns the same output

How do I end up fetching only the value inside a property say message ?

PS:
err.statusCode does return the correct value ie. "500".
err.name returns "StatusCodeError"(not "Error" that I see in the response)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant