0
votes

I have a backbone collection which is setup to fetch results (events in my case) from a URL and then perform a little bit of data manipulation on the response in a parse method. When there are results provided by the api (as follows), the fetch is successful and everything behaves as expected.

{
  events: [
   { event1... },
   { event2... },
   ...
  ]
}

However, when the resultset is empty (as follows), the fetch runs its error function instead of the success call, and never seems to execute my parse method at all.

{
  events: []
}

Is this behaving as expected? As in, should backbone be throwing the error when there are 0 results, and if so, is there any way of fixing this?

1
Sounds odd. Is the returned JSON valid? Is the http return code 200? What is the errorText and error of the error callback arguments?jevakallio
Thanks that seems to have resolved it. It turns out the API was returning 500 when there was no results. I didn't think to check (I didn't build it).Jonny Heavey

1 Answers

0
votes

This error was being triggered by the APIs HTTP response code (500). As a result, Backbone was behaving correctly.