title: Why is Easyuniv REST API not Handling Errors?
body: <p>I am writing a REST API and currently testing some things. I am trying to make it send an error response when it does not find anything in the database.</p>
  
  <p>The part that is running (because i am testing currently by just entering the url into my browser) is below:</p>
  
  <pre><code>    else if ($request-&gt;getHttpAccept() === 'xml')  
      {  
          if(isset($data['s']) &amp;&amp; isset($data['n'])) {
              $id = $db-&gt;getAlcoholIDByNameSize($data['n'], $data['s']);
              $prices = $db-&gt;pricesByAlcohol($id);
          }
          if(isset($id)) {
              $resData = array();
              if(!empty($prices)) {
                  foreach($prices as $p) {
                      $store = $db-&gt;store($p['store']);
                      array_push($resData, array('storeID' =&gt; $p['store'], 'store_name' =&gt; $store['name'], 'store_gps' =&gt; $store['gps'], 'price' =&gt; round($p['price'], 2)));
                  }
                  RestUtils::sendResponse(200, json_encode($resData), 'application/json'); 
              } else {
                  RestUtils::sendResponse(204, 'error', 'application/json'); 
              }
          } else {
              RestUtils::sendResponse(204, 'error', 'application/json'); 
          }
          //RestUtils::sendResponse(501, "xml response not implemented", 'application/xml');  
      }  
  </code></pre>
  
  <p>everything works fine if the queries return something to be stored in $id and $prices. If they do not exist in the database, however, it tries to load the page, and then goes back to the previous page you were on. You can see the behavior by going to:</p>
  
  <pre><code>http://easyuniv.com/API/alc/coorsa/2   &lt;-- works
  http://easyuniv.com/API/alc/coors/3    &lt;-- works
  http://easyuniv.com/API/alc/coorsa/5   &lt;-- doesn't work(or anything else, the two above are the only ones)
  </code></pre>
  
  <p>here is my sendResponse function:</p>
  
  <pre><code>   public static function sendResponse($status = 200, $body = '', $content_type = 'text/html')  
      {  
          $status_header = 'HTTP/1.1 ' . $status . ' ' . RestUtils::getStatusCodeMessage($status);  
          // set the status  
          header($status_header);  
          // set the content type  
          header('Content-type: ' . $content_type);  
  
          // pages with body are easy  
          if($body !== '')  
          {  
              $temp = json_decode($body);
              $body = json_encode(array('result' =&gt; array('status' =&gt; $status, 'message' =&gt; RestUtils::getStatusCodeMessage($status)), 'data' =&gt; $temp));
              // send the body  
              echo $body;  
              exit;  
          }  
          // we need to create the body if none is passed  
          else  
          {           
              $body = "else".json_encode(array('result' =&gt; array('status' =&gt; $status, 'message' =&gt; RestUtils::getStatusCodeMessage($status))));
  
              echo $body;  
              exit;  
          }  
      } 
  </code></pre>
  
  <p>I have tried debugging using echos but I cant seem to narrow down what the issue is. Any help would be appreciated, thanks.</p>