restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Restangular.one with empty 2nd parameter

Open lsanczyk opened this issue 10 years ago • 5 comments

If I use by mistake Restangular.one('endpoint','').get(), then I lost the default header 'Authorization' in the GET request. Thus the API returns an 'unauthorized' error (401) instead of, for example, a 'bad request' error (400).

lsanczyk avatar Mar 30 '16 05:03 lsanczyk

This sounds like a serverside problem, not a Restangular one? Can you elaborate on exactly what you're trying to do?

daviesgeek avatar Mar 30 '16 20:03 daviesgeek

Simply using the one method, with no problem if the 2nd parameter has length. But if it is an empty string, by mistake, the 'Authorization' header isn't sent in the GET request received by the API (I'm looking for it in the PHP $_SERVER array because is running in a Nginx server, not Apache, and must use a custom getallheaders function, but the header is there if the parameter has length). The rest basic headears remains ok, that's the only change.

PS: The header is setted using Restangular.setDefaultHeaders({'Authorization': 'string'}); or $http.defaults.headers.common['Authorization']='string';

lsanczyk avatar Mar 30 '16 22:03 lsanczyk

Ah. Okay. I understand now.

I tested this out in a Plunk and I don't seem to have the problem that you do. Can you take a look at this Plunk and let me know if this is what you're trying to do?

http://plnkr.co/edit/4iO7UyWjVAfgBsC7t9Ot?p=preview

daviesgeek avatar Mar 30 '16 22:03 daviesgeek

Sorry, my bad. I returned to an old version of my code to do more tests and try to help with the "bug", but I found that was related to a timing problem with asynchronous threads. The empty string parameter is working as expected. I proceed to punish myself Game of Thrones style: "Shame! Shame! Shame!"

lsanczyk avatar Mar 31 '16 18:03 lsanczyk

Lol. No problem :) Async stuff can be a pain. Am I good to close this issue?

daviesgeek avatar Mar 31 '16 22:03 daviesgeek