title: Handle syntax error in JSON coming from API
body: <p>Imagine the following syntax error in JSON (<code>, instead of :</code>):</p>
  
  <pre><code>[
      {
          "name": "anna",
          "email": "anna@gmail.com",
          "town", "london"
      },
  ...
  ]
  </code></pre>
  
  <p>I am wondering if it is possible to handle this error instead of getting an exception, getting the erroneous object, correct the error and go on with the correct version.</p>
  
  <p>Here is a part of my Angular service; I am trying to get text and not JSON data but it does not work...</p>
  
  <pre><code> angular.module('mine', [])
      .config(function($sceProvider) {
          // Completely disable SCE.  
          $sceProvider.enabled(false);
      })
      .config(['$sceDelegateProvider', function($sceDelegateProvider) {
          $sceDelegateProvider.resourceUrlWhitelist([
          'self',
          'http://www.mocky.io/v2/5807df4a10000004122b74e2'
          ]);
      }])
    .config(function ($httpProvider) {
          $httpProvider.interceptors.push(function($q) {
              return {
                  'request': function(config) {
                      config.headers.Accept = 'text/plain';
                      return config;
                  },
                  'response': function(response) {
                      try {
                          // try to parse it
                          response.data = JSON.parse(response.data);  
                      } catch (ex) {
                          // try to fix it
                          console.log("error " + ex);
                          console.log(response.data);
                          response.data = {fixed_data : "data"};
                      }
                      // return the corect data.
                      // note that the original response.data WILL BE CHANGED and this is expected.
                      return response;
                  }
              };
          });
    })
  
  
  
         angular.module('mine').factory('MyFactory', ['$http','$q',  function MyFactory($http,$q) {
          return {
              getData: function() {    
                  var deferred = $q.defer(),
                  config = {
                          params: { }
                      },
  
                  url="http://www.mocky.io/v2/5807df4a10000004122b74e2";          
  
                  $http.jsonp(url,config)
                  .then(              
                      function (response) {
                          deferred.resolve(response.data);
                      },  
                      function (error) {
                          console.log(error);
                          return $q.reject('Error retrieving data');
                      }
                  );
  
                  return deferred.promise;
              }
          };
   }]);
  </code></pre>
  
  <p><strong><em>Is there anyway of directing the above promise into the success callback, retrieving the erroneous JSON and correcting it? How may I code that according to the above example?</em></strong> </p>
  
  <p><strong><em>Or maybe something easier, how to retrieve text and not JSON data from <code>$http.jsonp</code> as not to be driven to the failure callback?</em></strong></p>