简体   繁体   中英

How can I catch and change the thrown exception message from facebook sdk?

I'm getting this exception from facebook SDK:

Fatal error: Uncaught OAuthException: (#506) Duplicate status message thrown in [...] src/base_facebook.php on line 1033

How can I catch the exception before it prints this message? I want to change it to something like this:

The response of the application still the same so we can't publish it in to your wall again : )

Btw, there is a method (below) that handles all the exceptions and I want this new message only for that especific case.

protected function throwAPIException($result) {
    $e = new FacebookApiException($result);
    switch ($e->getType()) {
      // OAuth 2.0 Draft 00 style
      case 'OAuthException':
        // OAuth 2.0 Draft 10 style
      case 'invalid_token':
        $message = $e->getMessage();
      if ((strpos($message, 'Error validating access token') !== false) ||
          (strpos($message, 'Invalid OAuth access token') !== false)) {
        $this->setAccessToken(null);
        $this->user = 0;
        $this->clearAllPersistentData();
      }
    }

    throw $e;
  }

Thanks.

You put the code that is throwing the Exception within a try block and then catch it with a catch block:

try
{
  // Code goes here
}

catch (OAuthException $e)
{
  // Stuff to do with exception
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM