Skip to content

Handling of getList with HTTP 204 and no body #159

Open
@unexist

Description

@unexist

Hey,

according to spec there must not be any body, when the server replies with HTTP 204. And in fact, chrome cancels a request, when there is data. This breaks the handling of restangular in this case:

ERROR Error: Response for getList SHOULD be an array and not an object or something else

This can be verified like this with he help of https://httpstat.us:

this.restangular.withConfig((RestangularConfigurer) => {
  RestangularConfigurer.setBaseUrl('https://httpstat.us');
}).all('204').getList();

Back then in 2014 there was a small fix for handling of 204: mgonto/restangular@6565c86

No idea if this ever worked, but int he current version data is of type Object, whenever the server sends no body and the check in the patch fails.

So my question before any pull request and whatsoever:

  • Is this error message required at all?
  • Is there any problem/side effect with always returning an array, when data isn't already one?

This works properly for me:

// support empty response for getList() calls (some APIs respond with 204 and empty body)
if (!isArray(data)) {
  data = [];
}

Here some facts about my system, although I don't think they make any difference:

Linux (Debian 9)
Version 70.0.3538.110 (Developer Build) built on Debian 9.6, running on Debian 9.6 (64-bit)

$ npm list | grep angular
@angular/core@7.0.4
@angular/forms@7.0.4
@angular/http@7.0.4
@angular/language-service@7.0.4
@angular/platform-browser@7.0.4
@angular/platform-browser-dynamic@7.0.4
@angular/router@7.0.4
@angular-devkit/core@0.5.13
@angular-devkit/schematics@0.5.13
@angular-devkit/core@0.5.13 deduped
ngx-restangular@4.0.1
$ npm version
{ 'twttr-angular': '0.0.0',
  npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.14.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.36',
  zlib: '1.2.11' }
$ node --version
v10.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionIssues with discussion

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions