Search code examples
ruby-on-railsajaxangularjsapiangular-resource

Angular ngResource handle 404 api error


i have a Rails API

Ex. example.com/v1/portfolio/{{ id }}

and i'm using AngularJS ngResource to handle the data with get.

myAppServices.factory('Portfolio', ['$resource', function($resource){
    return $resource('api/v1/portfolios/:id/', { id:'@id'}, {
        query: {
            method:'GET', 
            params:{id:'@id'},
            isArray:true
        }
    });
}]);

How can i handle the Not found 404 Error if the API does not have an Entry

Ex. example.com/v1/portfolio/blabla

i mean how can i make it 404 like when u enter http://www.google.com/sdfa check the network status code you'll find it 404.

For more information am using Prerender.io service to Render the website for Search Engines.


Solution

  • You should use the prerender-status-code meta tag to return a 404 to the crawler. The documentation is here: https://prerender.io/documentation/best-practices

    Basically, just add to the of the page if the page should return a 404 to crawlers. Prerender.io will detect that status code and return that to the crawler instead of a 200.

    Feel free to send an email to support@prerender.io if you have any other questions about that. We're happy to help!