title: PHP catch failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
body: <p>I am trying to do the following.</p>
  
  <p>When I try to access a service using oAuth, if I get an error, because I am using a wrong key, I want to not show the error messages, but instead send the user to the authentication page.</p>
  
  <p>However using a try catch fn does not work.</p>
  
  <p>This is my code:</p>
  
  <pre><code>$url = 'https://api.soundcloud.com/me.json?'.http_build_query(array(
          'oauth_token' =&gt; $token,
      ));
      //
      try{
          $user = json_decode(file_get_contents($url));
          return array(
              'uid' =&gt; $user-&gt;id,
              'nickname' =&gt; $user-&gt;username,
              'name' =&gt; $user-&gt;full_name,
              'location' =&gt; $user-&gt;country.' ,'.$user-&gt;country,
              'description' =&gt; $user-&gt;description,
              'image' =&gt; $user-&gt;avatar_url,
              'urls' =&gt; array(
                  'MySpace' =&gt; $user-&gt;myspace_name,
                  'Website' =&gt; $user-&gt;website,
              ),
          );
      }
      catch(Services_Soundcloud_Invalid_Http_Response_Code_Exception $e)
      {
          log_message('error', 'EXCEPTION: '.$e);
          return FALSE;
      }
  </code></pre>
  
  <p>I want this to either return the user array or FALSE.</p>
  
  <p>Any ideas? </p>