Welcome Guest, Not a member yet? Register   Sign In
How do I catch exceptions from a 3rd party plugin?
#1

[eluser]Unknown[/eluser]
Hi folks. I'm somewhat new to CodeIgniter, so be gentle if I'm missing something obvious. Smile

I have a function in a library making a call to the Facebook API using the Facebook plugin. Facebook is throwing an Uncaught OAuthException on line 547 of facebook_pi.php. I know why the exception is occurring and just want it to fail silently, but can't seem to catch the exception in my library.

Here's the code from my library that is calling the Facebook plugin:
Code:
# From my library's constructor:
$this->_ci =& get_instance();
$this->_ci->load->plugin('facebook');

# From a function in my library
    try {
      $result = $this->_ci->facebook->api(
        '/'.$post['userid'].'/feed/',
        'post',
        array(
          'message' => $post['message'],
          'link'    => $post['link']
        )
      );
    } catch (FacebookApiException $e) {
      error_log($e);
    }

As far as I can tell, my catch block is never getting called. Instead the error is just displayed on the screen.

Here's where the exception is getting generated in the Facebook plugin.
Code:
protected function _restserver($params) {
    // generic application level parameters
    $params['api_key'] = $this->getAppId();
    $params['format'] = 'json-strings';

    $result = json_decode($this->_oauthRequest(
      $this->getApiUrl($params['method']),
      $params
    ), true);

    // results are returned, errors are thrown
    if (is_array($result) && isset($result['error_code'])) {
      throw new FacebookApiException($result);
    }
    return $result;
  }

I have a feeling that I'm not catching the exception due to some namespace issue, but all of the examples like this I've found seem to use the same try/catch block that I'm using.

I basically just want to ignore any exception that might come from that try/catch block.

Can anyone point me in the right direction? Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB