Ionic Report error in case HTTP request result into a INVAILD_HOST or other HTTP errors

In my application user need to enter an URL for getting authenticated (which will be used for making a POST request). But in case if user enter invalid host URL then how to report connection error etc. in the $http. Below is the code which perform the same.


<label class="item item-input">
 <span class="input-label">Url</span>
 <input type="text" placeholder="" ng-model="loginData.crmUrl">


.controller('ActionsCtrl', ['$scope', '$ionicModal', '$http', '$state',
 function ($scope, $ionicModal, $http, $state) {
    . . .
    // Perform the respective operations
    $scope.doLogin = function () {
    console.log("LOGIN user: " + $scope.loginData.username + " - PW: " + $scope.loginData.password);
    console.log("Url is " + $scope.loginData.crmUrl);
    url: $scope.loginData.crmUrl + '/modules/Mobile/api.php',
    method: 'POST',
    headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
    data: 'username=' + $scope.loginData.username + '&password=' + $scope.loginData.password + '&_operation=login'
}).success(function (data, status, headers, config) {
if (data.success == true) {
console.log('Login is success');
 //alert('We are able to login');
  } else {
 alert('we failed');
}).error(function (data, status, headers, config) {
    . .. 

Now for example user enter http://localhost:8080 (which is an invalid address) I need to report an error for asking for a correct URL.
How I can achieve the same.