0

我在处理发布重复状态时捕获的错误时遇到问题...

try {
    $twitter->post_statusesUpdate(array('status' => $tweet));
} catch (EpiTwitterForbiddenException $e) {
    $msg = json_decode($e->getMessage());

//wp_die('Error: ' . $msg . ''); // Server errors out
wp_die('Error: ' . $e . ''); // Returns code in lower segment

    if ($msg->error != 'Status is a duplicate.') {

    //throw $e; // Disabled to prevent
    }
}

第一个 wp_die 出错,服务器崩溃 第二个 wp_die 返回:

Exception 'EpiTwitterForbiddenException' with message '{"errors":[{"code":187,"message":"Status is a duplicate"}]}' in /home5/site/public_html/wp-content/plugins/download/libs/api/EpiTwitter.php:265 Stack trace: #0 /home5/site/public_html/wp-content/plugins/download/libs/api/EpiTwitter.php(226): EpiTwitterException::raise(Object(EpiCurlManager), false) #1 /home5/site/public_html/wp-content/plugins/download/libs/api/EpiTwitter.php(127): EpiTwitterJson->__get('response') #2 /home5/site/public_html/wp-content/plugins/download/libs/api/EpiTwitter.php(109): EpiTwitter->request('POST', '/statuses/updat...', Array) #3 /home5/site/public_html/wp-content/plugins/download/download.php(109): EpiTwitter->__call('post_statusesUp...', Array) #4 /home5/site/public_html/wp-content/plugins/download/download.php(109): EpiTwitter->post_statusesUpdate(Array) #5 {main}

我应该如何解码以从其中获取错误?

4

1 回答 1

1

尝试...

// adding "true" as second argument forces json_decode to return an associative array
$msg = json_decode($e->getMessage(), true);
// print out the array
wp_die("error: " . print_r($msg, true));
于 2013-09-14T23:24:59.257 回答