开发者

PHP - how can I mute/replace this Exception handler?

开发者 https://www.devze.com 2023-02-19 10:35 出处:网络
I\'m using the Facebook PHP API, and around 1 time in 40 it dumps this exception on my webapp: Uncaught CurlException: 56: SSL read:

I'm using the Facebook PHP API, and around 1 time in 40 it dumps this exception on my webapp:

Uncaught CurlException: 56: SSL read: error:00000000:lib(0):func(0):reason(0), errno 104 thrown in ... on line 638

I'm not looking for a solution to what's causing the exception (already working on that), but for now I'd like to change it from dumping the exception on the page to either telling the user to refresh the page or refreshing the page automatically.

The exception is being thrown in this file: https://github.com/facebook/php-sdk/blob/master/src/facebook.php

This is the code I'd like to temporarily change to a refresh / refresh instruction:

    if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
  self::errorLog('Invalid or no certificate authority found, using bundled information');
  开发者_高级运维curl_setopt($ch, CURLOPT_CAINFO,
              dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
  $result = curl_exec($ch);
}

if ($result === false) {
  $e = new FacebookApiException(array(
    'error_code' => curl_errno($ch),
    'error'      => array(
      'message' => curl_error($ch),
      'type'    => 'CurlException',
    ),
  ));
  curl_close($ch);
  throw $e;
}


You could use TRY .. CATCH to catch CurlException, or FacebookApiException there. Or use set_exception_handler to catch any uncaught exception.


As strauberry said, you can stop throwing the exception. If the exception needs to be throw there, you can put the code that call this inside a try-catch and deal with the exception as you want.

Another option is to use the function set_exception_handler. This function will be called when an exception is thrown but nothing catch it.


You throw the Exception $e in the last line which causes the dumping. Instead you could do something like

echo "ERROR: " . $e->getMessage();
0

精彩评论

暂无评论...
验证码 换一张
取 消