Error 'Response for getList SHOULD be an array and not an object or something else' does not reject promise
See original GitHub issueI am developing the front-end of a client’s application, with no control over the backend beyond my ability to harass their developers.
At present, they have a bug in which under certain circumstances a request that usually returns a list []
is returning an object {}
. This is bad and will be fixed, but we would like to catch the error and display a friendly message in the meantime.
Restangular causes an exception to reach the console, but, unfortunately, the promise for the .getList
is never rejected:
promise = Restangular.all('endpoint')
.one('node', $state.params.nodeId)
.getList()
.then (channels) ->
# ...
$scope.loadingStatus = 'success'
, (error) ->
$scope.loadingStatus = 'error'
$scope.loadError = error
results in
Error: Response for getList SHOULD be an array and not an object or something else
but no rejection and hence no corresponding update to the $scope
error properties.
I believe Restangular should be rejecting the promise here. This is not like an assertion error which is useful to show you that you have made a coding error; in this case the error is not under our control and we want our users to get a nice error message.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top GitHub Comments
I get the idea and the work around. I’m not suggesting that you remove the error entirely, just make it reject the promise. You could also use console.warn to get the message across.
My beef is that a non-compliant server should not be able to force a client side library to literally break the entire page in production. That’s just bad defensive programming.
Adding interceptors for everything gets you around this issue, but it’s laborious, and requires the programmer to guess in advance which APIs might break. We just got lucky that our counterparts writing the API made this error while one us us had a console open.
I totally accept the argument for enforcing the method signature to help programmers. If Restangular just rejected the promise, and logged to console saying ‘oh no, the server broke the rules!’, every developer using the library would be defended against this edge case, and the method signature would still be enforced.
Michael On 22/02/2015 12:55 AM, “Mike Grabowski” notifications@github.com wrote:
@mbertolacci - kinda like open source discussions when to introduce a new feature! @mgonto?
I think that those two quotes are the perfect solution 😃
and…
I think that as long as this is very rare case to happen - it’s worth leaving an extra option for our users to handle that case, as in 10000-1 cases they might expect an error to be thrown 😃
I can’t say that adding response interceptors is complicated - it’s pretty clear in our docs and exposes deferred which can be easily rejected and I believe it is in many different cases by our users, e.g. to provide better error messages in some cases.