title: php - return error for js promise to catch
body: <p>Is that even possible to return some kind of error (ie using header()) from php file that is received by ajax call and reveived as error (via catch method?)</p>
  
  <p>consider such a php (example doesnt work correctly):</p>
  
  <pre><code>&lt;?php 
  
  session_start();
  
  $_SESSION['user_id'] = 1;
  
   header("Access-Control-Allow-Origin: *");
   header("Access-Control-Allow-Credentials: true");
   header("Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT");
   header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
  
  
  
  if ( $_SESSION['user_id'] == 0 ) {
          header('Content-Type: application/json');
          print json_encode(["test" =&gt; 123]);
      }
  else
      {
         header('HTTP/1.1 1337 Internal Server Kalreg');
         header('Content-Type: application/json; charset=UTF-8');
          die(json_encode(array('message' =&gt; 'ERROR', 'code' =&gt; 1337)));
  }
  ?&gt;
  </code></pre>
  
  <p>and js:</p>
  
  <pre><code>axios.get('loginStatus.php', { crossDomain: true })
          .then(function (response) {
          console.log(response);
          })
          .catch(function (error) {
            console.log(error);
          });
  
  
      }
    }
  </code></pre>
  
  <p>Now because $_SESSION['user_id'] is set to 1 server error is generated, and because of that catch in js should react in proper way. In fact it is not - in chrome-dev-tools i get an error:</p>
  
  <blockquote>
    <p>xhr.js?ec6c:178 OPTIONS
    <a href="http://192.168.0.15/game/src/server/loginStatus.php" rel="nofollow noreferrer">http://192.168.0.15/game/src/server/loginStatus.php</a> 500 (Internal
    Server Error) Failed to load
    <a href="http://192.168.0.15/game/src/server/loginStatus.php" rel="nofollow noreferrer">http://192.168.0.15/game/src/server/loginStatus.php</a>: Response for
    preflight has invalid HTTP status code 500.</p>
  </blockquote>
  
  <p>Is that possible? Or should i return just JSON file with error or not and manage it with .then not .catch?</p>
  
  <p>Kalreg.</p>