aliyun / api-gateway-nodejs-sdk

The API Gateway SDK for Node.js
MIT License
107 stars 23 forks source link

Missing response in error details #28

Open iampeterbanjo opened 4 years ago

iampeterbanjo commented 4 years ago

Given a request and response like the one below:

nock('https://test.cn:443', {"encodedQueryParams":true})
  .post('/user', {"name":"景全安"})
  .reply(400, {
    "code":400,
    "format":"json",
    "message":"{\"error\": \"Parameter \\\"email\\\" was missing from the request\"}"
   });

I would expect that the error thrown in client.js would include the original response object so that it can be handled correctly. But the error that is thrown only includes the code and headers. For example, when logged the error displays as:

Error: POST https://test.cn failed width code(400).

Please note that the message, "Parameter email was missing from the request" does not exist in the error.

This makes it difficult to use this client with APIs that return errors that are not in the header, for example, because of input validation.