I am currently writing an Angular application that communicates with the flickr API. In order to utilise the response from flickr you need to define a jsonFlickrFeed
callback function. Please see answer here for details on how this works
Everything is working fine in my angular app. I am getting the response and showing the data on the screen.
However, to improve UX I would like to show an error message to the user if the data does not load, but I cannot figure out how to display this message. The way I thought it would work, always logs an error the way the API works. Please see my attempt below:
app.controller('testCtrl', function (getFlickrData) {
var testCtrl = this;
this.loading = true;
this.error = false;
//call to get the data from Flickr
getFlickrData.getData().catch(function (err) {
//show error
console.log(err)
testCtrl.error = true;
})
.finally(function () {
// Hide loading spinner whether our call succeeded or failed.
testCtrl.loading = false;
});
//API requires jsonFlickrFeed callback function
jsonFlickrFeed = function(data){
console.log(data);
}
});
and here is the factory I am using to make the GET request to Flickr
app.factory('getFlickrData', function($http){
return{
getData: function(){
return $http.jsonp('https://api.flickr.com/services/feeds/photos_public.gne?tagmode=all&format=json');
}
}
});
The err logged in the console looks like this:
{data: undefined, status: 404, config: Object, statusText: "error"}
and finally here is the html which is always shown, even if the content loads successfully.
<div ng-show="testCtrl.error" class="error">
<p>Sorry but there has been an error with loading content. Please try again soon.</p>
</div>
I guess to sum up my question is how to check success/failure of a callback (possibly)
Here is a jsfiddle that may make it easier to see the problem I am trying to solve