Beispiel #1
0
 /**
  * @param \Exception $exception
  *
  * @return string
  */
 protected function buildLogMessage(\Exception $exception)
 {
     $message = $exception->getMessage() . "({$exception->getCode()})";
     if ($exception instanceof PhprestException && $exception->getDetails()) {
         $message .= ' Details :: ' . json_encode($exception->getDetails());
     }
     $message .= ' Stack trace :: ' . $exception->getTraceAsString();
     return $message;
 }
Beispiel #2
0
 public function testInstantiation()
 {
     $exception = new Exception('test message', 9, 201, [1, 2, 3]);
     $this->assertEquals('test message', $exception->getMessage());
     $this->assertEquals(9, $exception->getCode());
     $this->assertEquals(201, $exception->getStatusCode());
     $this->assertEquals([1, 2, 3], $exception->getDetails());
 }
Beispiel #3
0
 /**
  * @param \Exception $exception
  */
 public function __construct(\Exception $exception)
 {
     $this->code = $exception->getCode();
     $this->message = $exception->getMessage();
     if ($exception instanceof Exception) {
         $this->details = $exception->getDetails();
     }
 }
 public function displayError(\Exception $exception)
 {
     $originalException = $exception;
     $code = $exception->getCode();
     //if extended exception was thrown, we have additional details
     if ($exception instanceof ExceptionInterface) {
         $httpStatus = $exception->getHttpStatus();
         $details = $exception->getDetails();
     } else {
         $httpStatus = 500;
         $details = array();
     }
     $development = ini_get('display_errors') && APPLICATION_ENV === "development";
     $message = $exception->getMessage();
     //determine whether this is an error the user should see
     if (($code < 100000 || $code >= 200000) && !$development) {
         //exception code is in the range where the message should be
         //displayed to the user
         $message = "An unexpected error has occurred";
         $details['detail'] = "This might be the developer's fault. The developer has been notified of this occurrence";
     }
     //show exception details if in development //redundant conditional?
     if ($development) {
         $exceptions = array();
         do {
             $exceptions['exception'][] = array('message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString());
         } while ($exception = $exception->getPrevious());
         $details['exceptions'] = $exceptions;
     }
     //TODO attach to this event, email if not in user visible range
     $this->getEventManager()->trigger('displayError', $this, $originalException);
     $result = $this->getError($message, $details, $httpStatus, $code);
     return $this->display($result);
 }
Beispiel #5
0
 private function processExceptionFromRPCCall(ClientSession $session, InvocationMessage $msg, $registration, \Exception $e)
 {
     if ($e instanceof WampErrorException) {
         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
         $errorMsg->setErrorURI($e->getErrorUri());
         $errorMsg->setArguments($e->getArguments());
         $errorMsg->setArgumentsKw($e->getArgumentsKw());
         $errorMsg->setDetails($e->getDetails());
         $session->sendMessage($errorMsg);
         return;
     }
     $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
     $errorMsg->setErrorURI($registration['procedure_name'] . '.error');
     $errorMsg->setArguments([$e->getMessage()]);
     $errorMsg->setArgumentsKw($e);
     $session->sendMessage($errorMsg);
 }