$http message provides functions for handling success and errors:
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
In case of a server error or any other HTTP error, the error function will be triggered to catch the error.
If you need to provide feedback to the user or handle different scenarios, you can customize the data returned in the success method like this:
data {message: 'your message here', success: /*true or false*/, result: /*some data*/ }
Then in the success function:
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
if(data.success) {
// handle successful scenario
}
else {
// display error or notification
}
}).
error(function(data, status, headers, config) {
//handle error for status 400 or 500
});