public function renderAsRestAPI($request, \Exception $e)
 {
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     $fe = FlattenException::create($e);
     $data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
     return JsonResponse::create($data, 500);
 }
Esempio n. 2
0
 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Not Found';
     }
     parent::__construct($message, 404, $previous);
 }
Esempio n. 3
0
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Not Acceptable' will be the message
  * @param int $code Status code, defaults to 406
  */
 public function __construct($message = null, $code = 406)
 {
     if (empty($message)) {
         $message = 'Not Acceptable';
     }
     parent::__construct($message, $code);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Internal Server Error' will be the message
  * @param int $code Status code, defaults to 500
  */
 public function __construct($message = null, $code = 500)
 {
     if (empty($message)) {
         $message = 'Internal Server Error';
     }
     parent::__construct($message, $code);
 }
 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Unauthorized';
     }
     parent::__construct($message, 401, $previous);
 }
 public function __construct($message = '')
 {
     if (!$message) {
         $message = 'Unauthorized';
     }
     parent::__construct($message, 401);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Unavailable For Legal Reasons' will be the message
  * @param int $code Status code, defaults to 451
  */
 public function __construct($message = null, $code = 451)
 {
     if (empty($message)) {
         $message = 'Unavailable For Legal Reasons';
     }
     parent::__construct($message, $code);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Service Unavailable' will be the message
  * @param int $code Status code, defaults to 503
  */
 public function __construct($message = null, $code = 503)
 {
     if (empty($message)) {
         $message = 'Service Unavailable';
     }
     parent::__construct($message, $code);
 }
Esempio n. 9
0
 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Forbidden';
     }
     parent::__construct($message, 403, $previous);
 }
Esempio n. 10
0
 /**
  * @param string          $location
  * @param integer         $statusCode
  * @param string          $message
  * @param \Exception|null $previous
  */
 public function __construct($location, $statusCode = 302, $message = '', \Exception $previous = null)
 {
     if ($statusCode < 300 || $statusCode >= 400) {
         throw new \InvalidArgumentException('Invalid HTTP redirect status code: ' . $statusCode);
     }
     parent::__construct($statusCode, ['Location' => $location], $message, $previous);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Invalid  CSRF Token' will be the message
  * @param int $code Status code, defaults to 403
  */
 public function __construct($message = null, $code = 403)
 {
     if (empty($message)) {
         $message = 'Invalid  CSRF Token';
     }
     parent::__construct($message, $code);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Unauthorized' will be the message
  * @param int $code Status code, defaults to 401
  */
 public function __construct($message = null, $code = 401)
 {
     if (empty($message)) {
         $message = 'Unauthorized';
     }
     parent::__construct($message, $code);
 }
Esempio n. 13
0
 public function __construct($message = '')
 {
     if (!$message) {
         $message = 'Not Found';
     }
     parent::__construct($message, 404);
 }
Esempio n. 14
0
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Bad Request' will be the message
  * @param int $code Status code, defaults to 400
  */
 public function __construct($message = null, $code = 400)
 {
     if (empty($message)) {
         $message = 'Bad Request';
     }
     parent::__construct($message, $code);
 }
Esempio n. 15
0
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Conflict' will be the message
  * @param int $code Status code, defaults to 409
  */
 public function __construct($message = null, $code = 409)
 {
     if (empty($message)) {
         $message = 'Conflict';
     }
     parent::__construct($message, $code);
 }
Esempio n. 16
0
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Forbidden' will be the message
  * @param int $code Status code, defaults to 403
  */
 public function __construct($message = null, $code = 403)
 {
     if (empty($message)) {
         $message = 'Forbidden';
     }
     parent::__construct($message, $code);
 }
 public function __construct($message = '')
 {
     if (!$message) {
         $message = 'Forbidden';
     }
     parent::__construct($message, 403);
 }
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Method Not Allowed' will be the message
  * @param int $code Status code, defaults to 405
  */
 public function __construct($message = null, $code = 405)
 {
     if (empty($message)) {
         $message = 'Method Not Allowed';
     }
     parent::__construct($message, $code);
 }
Esempio n. 19
0
 /**
  * Constructor
  *
  * @param string|null $message If no message is given 'Gone' will be the message
  * @param int $code Status code, defaults to 410
  */
 public function __construct($message = null, $code = 410)
 {
     if (empty($message)) {
         $message = 'Gone';
     }
     parent::__construct($message, $code);
 }
Esempio n. 20
0
 /**
  * Code and message positions are reverted.
  *
  * @param int    $code
  * @param string $message
  */
 public function __construct($code = null, $message = "")
 {
     if (empty($code) && empty($this->code)) {
         $code = self::NOT_FOUND;
     }
     parent::__construct($message, $code);
 }
Esempio n. 21
0
 /**
  * Class constructor.
  *
  * @param string          $location    The redirect URL.
  * @param int             $statusCode  The HTTP status code, 3XX.
  * @param string          $message     An optional exception message for debugging.
  * @param \Throwable|null $previous    An optional previous exception for chaining.
  *
  * @throws \RuntimeException
  */
 public function __construct($location, $statusCode = 302, $message = '', \Throwable $previous = null)
 {
     if ($statusCode < 300 || $statusCode >= 400) {
         throw new \RuntimeException('Invalid HTTP redirect status code: ' . $statusCode);
     }
     parent::__construct($statusCode, ['Location' => $location]);
 }
Esempio n. 22
0
 public function __construct($message = null, $code = 404)
 {
     if (empty($message)) {
         $message = 'Not Found';
     }
     parent::__construct($message, $code);
 }
 /**
  * Constructor.
  *
  * @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried
  * @param string     $message    The internal exception message
  * @param Exception  $previous   The previous exception
  * @param integer    $code       The internal exception code
  */
 public function __construct($retryAfter = null, $message = null, \Exception $previous = null, $code = 0)
 {
     $headers = array();
     if ($retryAfter) {
         $headers = array('Retry-After' => $retryAfter);
     }
     parent::__construct(429, $message, $previous, $headers, $code);
 }
 /**
  * @param int $retry_after
  * @param string $message
  * @param int $code
  * @param \Exception $previous
  */
 public function __construct($retry_after = 0, $message = '', $code = 0, \Exception $previous = null)
 {
     $headers = [];
     if ($retry_after) {
         $headers = ['Retry-After' => $retry_after];
     }
     parent::__construct(429, $message, $headers, $code, $previous);
 }
 public function __construct($apiCode, $params = array(), $message = null)
 {
     $this->apiCode = $apiCode;
     $this->params = $params;
     if (empty($message)) {
         $message = 'API exception occurred';
     }
     parent::__construct($message, 418);
 }
Esempio n. 26
0
 function exception(Exception $e)
 {
     if (ob_get_length() != false) {
         @ob_end_clean();
     }
     $et = typeOf($e);
     if ($et == 'FileNotFoundException' || $et == 'NavigationException') {
         response::setStatus(404);
         header('HTTP/1.1 404 Not Found', true);
         printf("<h1>404: Not Found</h1>");
         return;
     }
     if ($et == 'HttpException') {
         response::setStatus($e->getCode());
         $code = $e->getMessage();
         list($code) = explode(':', $code);
         $code = str_replace('Error ', '', $code);
         $msg = HttpException::getHttpMessage($code);
         header('HTTP/1.1 ' . $code . ' ' . $msg . ' ' . $msg);
         printf("<h1>%s: %s</h1>\n<pre>%s</pre>", $code, $msg, $msg);
         return;
     }
     response::setStatus(500);
     logger::emerg("Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine());
     header('HTTP/1.1 501 Server Error', true);
     $id = uniqid();
     $dbg = sprintf("Unhandled exception: (%s) %s\n  in %s:%d", get_class($e), $e->getMessage(), str_replace(SYS_PATH, '', $e->getFile()), $e->getLine()) . Console::backtrace(0, $e->getTrace(), true) . "\n" . "Loaded modules:\n" . ModuleManager::debug() . "\n" . request::getDebugInformation();
     logger::emerg($dbg);
     if (config::get('lepton.mvc.exception.log', false) == true) {
         $logfile = config::get('lepton.mvc.exception.logfile', "/tmp/" . $_SERVER['HTTP_HOST'] . "-debug.log");
         $log = "=== Unhandled Exception ===\n\n" . $dbg . "\n";
         $lf = @fopen($logfile, "a+");
         if ($lf) {
             fputs($lf, $log);
             fclose($lf);
         }
     }
     $ico_error = resource::get('warning.png');
     header('content-type: text/html; charset=utf-8');
     echo '<html><head><title>Unhandled Exception</title>' . self::$css . self::$js . '</head><body>' . '<div id="box"><div id="left"><img src="' . $ico_error . '" width="32" height="32"></div><div id="main">' . '<h1>An Unhandled Exception Occured</h1>' . '<hr noshade>' . '<p>This means that something didn\'t go quite go as planned. This could be ' . 'caused by one of several reasons, so please be patient and try ' . 'again in a little while.</p>';
     if (config::get('lepton.mvc.exception.feedback', false) == true) {
         echo '<p>The administrator of the website has been notified about this error. You ' . 'can help us find and fix the problem by writing a line or two about what you were doing when this ' . 'error occured.</p>';
         echo '<p id="feedbacklink"><a href="javascript:doFeedback();">If you would like to assist us with more information, please click here</a>.</p>';
         echo '<div id="feedback" style="display:none;"><p>Describe in a few short lines what you were doing right before you encountered this error:</p><form action="/errorevent.feedback/' . $id . '" method="post"><div><textarea name="text" style="width:100%; height:50px;"></textarea></div><div style="padding-top:5px; text-align:right;"><input type="button" value=" Close " onclick="closeFeedback();"> <input type="submit" value=" Submit Feedback "></div></form></div>';
     }
     if (config::get('lepton.mvc.exception.showdebug', false) == true) {
         echo '<hr noshade>' . '<a href="javascript:toggleAdvanced();">Details &raquo;</a>' . '<pre id="advanced" style="display:none; height:300px;">' . $dbg . '</pre>';
     }
     echo '<div>' . '</body></html>';
 }
 /**
  * Constructor.
  *
  * @param string     $message  The internal exception message
  * @param \Exception $previous The previous exception
  * @param int        $code     The internal exception code
  */
 public function __construct($message = null, \Exception $previous = null, $code = 0)
 {
     parent::__construct(428, $message, $previous, array(), $code);
 }
 /**
  * Constructor.
  * @param string $message error message
  * @param integer $code error code
  * @param \Exception $previous The previous exception used for the exception chaining.
  */
 public function __construct($message = null, $code = 0, \Exception $previous = null)
 {
     parent::__construct(415, $message, $code, $previous);
 }
Esempio n. 29
-1
 public function run()
 {
     if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
         // action has been invoked not from error handler, but by direct route, so we display '404 Not Found'
         $exception = new HttpException(404, Yii::t('yii', 'Page not found.'));
     }
     if ($exception instanceof HttpException) {
         $code = $exception->statusCode;
     } else {
         $code = $exception->getCode();
     }
     if ($exception instanceof Exception) {
         $name = $exception->getName();
     } else {
         $name = $this->defaultName ?: Yii::t('yii', 'Error');
     }
     if ($code) {
         $name .= " (#{$code})";
     }
     if ($exception instanceof UserException) {
         $message = $exception->getMessage();
     } else {
         $message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         return "{$name}: {$message}";
     } else {
         return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
     }
 }
Esempio n. 30
-1
 /**
  * Converts an exception into an array.
  * @param \Exception $exception the exception being converted
  * @return array the array representation of the exception.
  */
 protected function convertExceptionToArray($exception)
 {
     if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
         $exception = new HttpException(500, 'There was an error at the server.');
     }
     $array = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
     if ($exception instanceof LBUserException) {
         $array['data'] = $exception->getErrors();
     }
     return $array;
 }