Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of getList with HTTP 204 and no body #159

Open
unexist opened this issue Nov 28, 2018 · 1 comment
Open

Handling of getList with HTTP 204 and no body #159

unexist opened this issue Nov 28, 2018 · 1 comment
Labels
discussion Issues with discussion

Comments

@unexist
Copy link

unexist commented Nov 28, 2018

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/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular-devkit/[email protected]
@angular-devkit/[email protected]
@angular-devkit/[email protected] deduped
[email protected]
$ 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
@rshchpkn
Copy link
Collaborator

Unfortunately, I can't find any strict definitions about rest pattern. From my understanding, collection endpoint shouldn't return 204 status. If there are no entities to return response should be an empty array. 204 status is used only for entities deletion. Will be great if you can share any docs or articles about 204 status response from collection endpoint

@rshchpkn rshchpkn added the discussion Issues with discussion label Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Issues with discussion
Projects
None yet
Development

No branches or pull requests

2 participants