abao icon indicating copy to clipboard operation
abao copied to clipboard

Error response body is null?

Open plroebuck opened this issue 9 years ago • 2 comments

So I can't explain this...

  GET /api/heatmaps/{chm}/datasets/{ds}/data -> 500
before-hook-GET-api-heatmaps-{chm}-datasets-{ds}-data-500 (toobiglabel)
    1) Validate response code and body
after-hook-GET-api-heatmaps-{chm}-datasets-{ds}-data-500 (toobiglabel)
************************************************
test.response: { status: '500',
  schema: 
   { '$schema': 'http://json-schema.org/draft-04/schema',
     id: 'http://jsonschema.net',
     type: 'object',
     required: true,
     properties: { code: [Object], message: [Object] } },
  headers: null,
  body: null }
test.response.body: null
    2) "after all" hook
 2 failing

  1) GET /api/heatmaps/{chm}/datasets/{ds}/data -> 500 Validate response code and body:
     Uncaught AssertionError: Got unexpected response code:
label(s) not found
Error: expected 400 to equal '500'


  2) GET /api/heatmaps/{chm}/datasets/{ds}/data -> 500 "after all" hook:
     TypeError: Cannot read property 'code' of null
    at hooks/test_data_hooks.js:93:28

While I believe the underlying C code may be responsible for the 400 vs. 500 issue, my issue lies with the second test's lack of a test.response.body after its death...

hooks.before('GET /api/heatmaps/{chm}/datasets/{ds}/data -> 500', function(test, done) {
  test.request.params.chm = 'kda-gbm-affy-analysis-012-newnorm';
  test.request.params.ds  = 'tcga-topg';
  test.request.query['labels'] = Array(4096).join('x');  // :TBD: Why don't larger values this crash it?
  test.request.headers['Accept'] = 'text/tab-separated-values,*/*;q=0';
  console.log('before-hook-GET-api-heatmaps-{chm}-datasets-{ds}-data-500 (toobiglabel)');
  return done();
});

hooks.after('GET /api/heatmaps/{chm}/datasets/{ds}/data -> 500', function(test, done) {
  console.log('after-hook-GET-api-heatmaps-{chm}-datasets-{ds}-data-500 (toobiglabel)');
  // :TBD: Think vendor code is incorrect here...
  console.log('************************************************');
  console.log("test.response:", test.response);
  console.log("test.response.body:", test.response.body);
  assert(test.response.body.code === 'Internal');
  test.response.status = parseInt(test.response.status, 10);
  assert(test.response.status === 500);
  return done();
});

Why doesn't this get the same response body as I get from command line?

$ curl -sS 'http://127.0.0.1:8080/api/heatmaps/kda-gbm-affy-analysis-012-newnorm/datasets/tcga-topg/data?labels=nosuchlabel'
{"code":"BadRequestError","message":"label(s) not found"}

plroebuck avatar Jan 08 '16 13:01 plroebuck

+1

I have simple router in Express which returns json object when I send request using kinda Postman tool, but when I log test.response in after hook and launch tests, I get that body equals null (mentioned as default in documentation). Where is my body?

My env: abao: 0.5.0 express: 4.16.3

@cybertk

peramor avatar Jun 26 '18 10:06 peramor

Wow, a post from sooo long, long ago.

Your body is returned in the request response internally, but abao has no way to make use of it. For it to do so, you must provide JSON schema representing the response body. Only schema-validated response bodies get through...

plroebuck avatar Jun 29 '18 12:06 plroebuck