Amareis / another-rest-client

Simple pure TypeScript REST API client that makes your code lesser and more beautiful than without it.
MIT License
174 stars 17 forks source link

Null response #4

Closed TrendyTim closed 7 years ago

TrendyTim commented 7 years ago

Firstly i like your library its small and works (i tried jquery.rest but it seems to force parameters on posts), but yours worked straight off, although i do slightly prefer how they support the .post(obj).done(fnDone).fail(fnFail) appraoch rather than .then(fnDone, fnFail) but all in all i still prefer yours.

Now the tiny issue (and fix?):

In WebAPI if you "return Ok()" or StatusCode 204 (no content) it doesnt set a content type, so there is an exception when your library tries to parse the content type ("Cannot read property 'split' of null(…)" on line 140).

This small mod appears to fix it without any unforeseen issues (though you can fix it in anyway you like obviously, since i do not have the time to learn to submit patches just wanted to make the fix as painless as possible).

from var responseContentType = xhr.getResponseHeader('Content-Type').split(';')[0]; to var responseContentType = (xhr.getResponseHeader('Content-Type') || "").split(';')[0];