Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<div ng-controller="MyCtrl">
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($http) {
//success
$http({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/posts',
headers: {
"Content-Type": "application/json",
"my-token": "mytoken",
}
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log('succcess');
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log('error 1');
});
// 404 - not found
$http({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/i/do/not/exist',
headers: {
"Content-Type": "application/json",
"my-token": "mytoken",
}
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log('succcess');
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status
console.log('error 2');
console.log(response.status);
});
// 404 - not found
$http({
method: 'GET',
url: 'some-suptid-url',
headers: {
"Content-Type": "application/json",
"my-token": "mytoken",
}
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log('succcess');
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status
console.log('error 3');
console.log(response.status);
});
});