예제 #1
0
 public function testGetCauseException()
 {
     $cause = new Exception('foo bar');
     $e = new PEAR_Exception('I caught an exception', $cause);
     $this->assertNotNull($e->getCause());
     $this->assertInstanceOf('Exception', $e->getCause());
     $this->assertEquals($cause, $e->getCause());
 }
예제 #2
0
 /**
  * @param \PEAR_Exception $e
  *   An unhandled exception.
  * @param array $apiRequest
  *   The full description of the API request.
  * @return array
  *   API response.
  */
 public function formatPearException($e, $apiRequest)
 {
     $data = array();
     $error = $e->getCause();
     if ($error instanceof \DB_Error) {
         $data["error_code"] = \DB::errorMessage($error->getCode());
         $data["sql"] = $error->getDebugInfo();
     }
     if (!empty($apiRequest['params']['debug'])) {
         if (method_exists($e, 'getUserInfo')) {
             $data['debug_info'] = $error->getUserInfo();
         }
         if (method_exists($e, 'getExtraData')) {
             $data['debug_info'] = $data + $error->getExtraData();
         }
         $data['trace'] = $e->getTraceAsString();
     } else {
         $data['tip'] = "add debug=1 to your API call to have more info about the error";
     }
     return $this->createError($e->getMessage(), $data, $apiRequest);
 }