guylabs / angular-spring-data-rest

An AngularJS module to ease the work with a Spring Data REST backend.

Home Page:http://guylabs.ch/project/angular-spring-data-rest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling HTTP code 204

rkusuma opened this issue · comments

Hi @guylabs

Somehow API will return 204 rather than 404 for unknown links.
How can i handle this 204 code ? Now when i get 204 all of request will be break and nothing happened.

Thanks

Hi,

do you use Spring Data REST? If not I think I cannot give you support for that as this library is for Spring Data REST and the other usages are not supported and I think it is not a proper REST API if it returns a 204 instead of a 404.

You are able to implement your own fetchFunction (https://github.com/guylabs/angular-spring-data-rest#exchange-the-underlying-fetch-function) and then change this part here: https://github.com/guylabs/angular-spring-data-rest/blob/master/src/angular-spring-data-rest-provider.js#L105.

Then you can handle the 204 responses.

Thanks and regards,

Guy

Yes we use Spring Data REST.
Initialy we return 404.. but that's make log console browser full of 404 log, so we change to 204.

If i implement my own fetchFunction, i can't use your processData function.

@guylabs
What i want if there is 204 code, i want append that link to the data with null value.
The code is something like this:

if (responseData.status == 204) {
    return $injector.get("$q").when(data).then(function() {
        data[key] = null;
    });
}

and add it in https://github.com/guylabs/angular-spring-data-rest/blob/master/src/angular-spring-data-rest-provider.js#L93

What do you think ?

Well in my opinion it is not a good idea to add this to the core as a 204 means something completely different and its not the standard how REST should be used.

And this is not Angular which logs them, but the browser itself, and therefore I wouldn't change the semantics of REST just to avoid these kind of logs. The normal users will never see these logs anyway. Here some links how to solve it in Chrome:

https://stackoverflow.com/questions/24207143/angular-avoid-console-trace-on-http-error
https://stackoverflow.com/questions/14337351/can-i-prevent-the-chrome-developer-tools-console-from-logging-image-404-errors/14427545#14427545

So therefore I would close this issue if it is ok with you.

Thanks and regards,

Guy

I see.. i'm ok with that..
last thing.. if i get 404 that means you skip that link?
For example:

SpringDataRestAdapter.process(response, ['link', 'link2', 'link3']).then(function(result) {
    ....
});

if link2 get 404.. result will only have link and link2 or skip all links?

Well as you see it here: https://github.com/guylabs/angular-spring-data-rest/blob/master/src/angular-spring-data-rest-provider.js#L105

If one of those return a 404 then this link won't be fetched but the others will. So then I close the issue.

Thanks for using the component! :)

Regards,

Guy

👍
I really like this angular-spring-data-rest. It helps me a lot.

Thanks Guy

Thanks for the praise :).

Regards,

Guy