MainUI: How to handle HTTP status 204?

I’m actually trying to figure out something else, but my browser console gets absolute hammered with Uncaught (in promise) parseerror when I browse Things.

After some digging, it comes down to ThingResource doing this when no entry is found for whatever the resource is (like firmware):

return Response.status(Status.NO_CONTENT).build();

It returns HTTP status 204 “No Content” instead of, for example, an empty array. I’ve done some online searching, and there are many opinions about whether this is right or wrong. I have no opinion, I see that it’s convenient for the server to not have to generate content in this situation.

However, this isn’t received well on the other side, for example here:

          this.$oh.api.get('/rest/things/' + this.thingId + '/firmwares').then(firmwareData => {
            this.firmwares = firmwareData
          })

The problem, as far as I can understand, is that 204 is considered a success, which means that Vue, F7, or some other entity (it’s not quite clear to me what does this handling) tries to parse a JSON from nothing. The result is parseerror.

It’s quite annoying to have the browser console filled with these red errors with stack traces and all, and I think it should be handled another way.

The question is, I guess, should the server be modified to send an actual empty response (e.g. [] if the result is supposed to be an array), or should MainUI be modified to handle this gracefully? Can it? In a way, there’s no “universal way” to handle it, because it could mean that the result should be an empty string, an empty array, an empty object? If there was a “catch clause” for a specific HTTP status, it could easily be done, but I haven’t found a way to do this. It seems like a promise is either success or error, nothing in between.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.