/**
  * @param string     $resource       The resource that could not be imported
  * @param string     $sourceResource The original resource importing the new resource
  * @param int        $code           The error code
  * @param \Exception $previous       A previous exception
  */
 public function __construct($resource, $sourceResource = null, $code = null, $previous = null)
 {
     $message = '';
     if ($previous) {
         // Include the previous exception, to help the user see what might be the underlying cause
         // Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
         if ('.' === substr($previous->getMessage(), -1)) {
             $trimmedMessage = substr($previous->getMessage(), 0, -1);
             $message .= sprintf('%s', $trimmedMessage) . ' in ';
         } else {
             $message .= sprintf('%s', $previous->getMessage()) . ' in ';
         }
         $message .= $resource . ' ';
         // show tweaked trace to complete the human readable sentence
         if (null === $sourceResource) {
             $message .= sprintf('(which is loaded in resource "%s")', $this->varToString($resource));
         } else {
             $message .= sprintf('(which is being imported from "%s")', $this->varToString($sourceResource));
         }
         $message .= '.';
         // if there's no previous message, present it the default way
     } elseif (null === $sourceResource) {
         $message .= sprintf('Cannot load resource "%s".', $this->varToString($resource));
     } else {
         $message .= sprintf('Cannot import resource "%s" from "%s".', $this->varToString($resource), $this->varToString($sourceResource));
     }
     // Is the resource located inside a bundle?
     if ('@' === $resource[0]) {
         $parts = explode(DIRECTORY_SEPARATOR, $resource);
         $bundle = substr($parts[0], 1);
         $message .= ' ' . sprintf('Make sure the "%s" bundle is correctly registered and loaded in the application kernel class.', $bundle);
     }
     parent::__construct($message, $code, $previous);
 }
Example #2
0
 public function run()
 {
     if (Yii::$app->response->format == Response::FORMAT_HTML) {
         if ($this->debug || null === $this->exceptionView) {
             $file = $this->errorHandler->exceptionView;
             $this->response->data = $this->errorHandler->renderFile($file, ['exception' => $this->exception]);
             return $this->response;
         } else {
             return $this->controller->render($this->exceptionView, ['exception' => $this->exception]);
         }
     }
     if ($this->exception instanceof HttpException) {
         $code = $this->exception->statusCode;
     } elseif ($this->exception instanceof ResultsException || $this->exception instanceof UserException) {
         $code = $this->exception->getCode();
     } else {
         $code = 500;
     }
     if ($this->exception instanceof ResultsException) {
         $isSuccess = $this->exception->isSuccess;
     } else {
         $isSuccess = false;
     }
     $data = $this->exception instanceof ResultsException ? $this->exception->data : null;
     if ($this->debug) {
         $debugBacktrace = $this->convertExceptionToArray($this->exception);
     } else {
         $debugBacktrace = null;
     }
     return $this->controller->formatResults($code, $data, $isSuccess, $debugBacktrace, $this->exception->getMessage());
 }
Example #3
0
function handler_exception(Exception $e)
{
    if (APPLICATION_ENV == 'testing') {
        print $e->getMessage() . PHP_EOL;
        return;
    }
    error_log($e->getMessage());
    if (defined('BB_MODE_API')) {
        $code = $e->getCode() ? $e->getCode() : 9998;
        $result = array('result' => NULL, 'error' => array('message' => $e->getMessage(), 'code' => $code));
        print json_encode($result);
        return false;
    }
    $page = "<!DOCTYPE html>\n    <html lang=en>\n    <meta charset=utf-8>\n    <title>Error</title>\n    <style>\n    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;min-height:180px;padding:30px 0 15px}* > body{padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0} em{font-weight:bold}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}pre{ width: 100%; overflow:auto; }\n    </style>\n    <a href=//www.boxbilling.com/ target='_blank'><img src='https://sites.google.com/site/boxbilling/_/rsrc/1308483006796/home/logo_boxbilling.png' alt='BoxBilling' style='height:60px'></a>\n    ";
    $page = str_replace(PHP_EOL, "", $page);
    print $page;
    if ($e->getCode()) {
        print sprintf('<p>Code: <em>%s</em></p>', $e->getCode());
    }
    print sprintf('<p>%s</p>', $e->getMessage());
    print sprintf('<p><a href="http://www.boxbilling.com/docs/search.html?q=%s" target="_blank">Look for detailed error explanation</a></p>', urlencode($e->getMessage()));
    if (defined('BB_DEBUG') && BB_DEBUG) {
        print sprintf('<em>%s</em>', 'Set BB_DEBUG to FALSE, to hide the message below');
        print sprintf('<p>Class: "%s"</p>', get_class($e));
        print sprintf('<p>File: "%s"</p>', $e->getFile());
        print sprintf('<p>Line: "%s"</p>', $e->getLine());
        print sprintf('Trace: <pre>%s</pre>', $e->getTraceAsString());
    }
}
 protected function exceptionHandler(\Exception $e)
 {
     $response = new Response();
     $code = $e instanceof IHttpExpection ? $e->getCode() : Response::CODE_INTERNAL_SERVER_ERROR;
     $response->setStatusCode($code, $e->getMessage())->setBody($e->getMessage());
     return $response;
 }
Example #5
0
 protected function getErrorDetails(\Exception $exception, $code)
 {
     if (isset($this->exceptionMessages[$code])) {
         $error = $this->exceptionMessages[$code];
     } else {
         $error = $exception->getMessage();
     }
     if ($this->debug) {
         $message = $exception->getMessage();
         if (empty($message)) {
             $message = $error;
         }
         $class = get_class($exception);
         $file = $exception->getFile();
         $line = $exception->getLine();
         $trace = $exception->getTrace();
     } else {
         $message = $error;
         $class = 'Exception';
         $file = '';
         $line = '';
         $trace = array();
     }
     $result = array('error' => $error, 'message' => $message, 'code' => $code, 'class' => $class, 'file' => $file, 'line' => $line, 'trace' => $trace);
     return $result;
 }
 public function action_show()
 {
     $status = $this->error instanceof HttpException ? $this->error->getStatus() : '500 Internal Server Error';
     $data = $this->error instanceof HttpException ? $this->error->getData() : [];
     $this->response->add_header('HTTP/1.1 ' . $status);
     $displayErrors = $this->pixie->getParameter('parameters.display_errors', false);
     $showErrors = false;
     if ($this->error instanceof HttpException) {
         $message = $this->error->getMessage();
         if ($this->error->getCode() >= 400 || $this->error->getCode() < 100) {
             $showErrors = $displayErrors;
         }
     } else {
         if ($this->error instanceof SQLException) {
             if ($this->error->isVulnerable() && !$this->error->isBlind()) {
                 $showErrors = true;
                 $message = $this->error->getMessage();
             } else {
                 $message = "Error";
             }
         } else {
             $message = $this->error->getMessage();
             $showErrors = $displayErrors;
         }
     }
     $this->response->body = array_merge(['message' => $message, 'code' => $this->error->getCode(), 'trace' => $showErrors ? $this->error->getTraceAsString() : ""], $data);
 }
Example #7
0
 public static function sendExceptionByMail(Exception $e, $from, $to)
 {
     // generate mail datas
     $subject = '[' . MAIN_URL . ':' . CONFIG_ENV . '] Exception Report: ' . wordlimit_bychar($e->getMessage(), 50);
     $body = $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine();
     // sned mail throw Zend_Mail
     $mail = new Zend_Mail();
     $mail->setSubject($subject)->setFrom($from)->setBodyText($body);
     $emails = explode(' ', $to);
     foreach ($emails as $email) {
         $mail->addTo($email);
     }
     $att = $mail->createAttachment(var_export($_GET, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'GET.txt';
     $att = $mail->createAttachment(var_export($_POST, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'POST.txt';
     // send session dump only if exists
     if (session_id() != null) {
         $att = $mail->createAttachment(var_export($_SESSION, true), Zend_Mime::TYPE_TEXT);
         $att->filename = 'SESSION.txt';
     }
     $att = $mail->createAttachment(var_export($_SERVER, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'SERVER.txt';
     $att = $mail->createAttachment($e->getTraceAsString(), Zend_Mime::TYPE_TEXT);
     $att->filename = 'backtraceExeption.txt';
     $mail->send();
 }
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, \Exception $e)
 {
     $this->response = app(Response::class);
     // Model not found
     if ($e instanceof ModelNotFoundException) {
         return $this->response->errorNotFound(['title' => 'No query results', 'code' => Error::CODE_RESOURCE_NOT_FOUND]);
     }
     // Wrongs argument
     if ($e instanceof InvalidArgumentException) {
         return $this->response->errorWrongArgs([$e->getMessage()]);
     }
     // Validator
     if ($e instanceof ValidatorException) {
         return $this->response->errorWrongArgsValidator($e->errors());
     }
     if ($e instanceof AuthorizationException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     // Route not found
     if ($e instanceof NotFoundHttpException) {
         return $this->response->errorNotFound();
     }
     //  Method not allowed
     if ($e instanceof MethodNotAllowedHttpException) {
         return $this->response->errorMethodNotAllowed();
     }
     if ($e instanceof InvalidRequestException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     if ($e instanceof AccessDeniedException) {
         return $this->response->errorUnauthorized([$e->getMessage()]);
     }
     return parent::render($request, $e);
 }
 /**
  * Echoes an exception for the web.
  *
  * @param \Exception $exception The exception
  * @return void
  */
 protected function echoExceptionWeb(\Exception $exception)
 {
     if ($exception instanceof Exception) {
         $statusCode = 400;
         $json = ['status' => 'invalid_request', 'reason' => $exception->getMessage()];
     } elseif ($exception instanceof \TYPO3\Flow\Security\Exception) {
         $statusCode = 403;
         $json = ['status' => 'unauthorized', 'reason' => $exception->getMessage()];
     } else {
         $statusCode = 500;
         if ($exception instanceof FlowException) {
             $statusCode = $exception->getStatusCode();
         }
         $json = ['status' => 'error', 'reason' => $exception->getMessage(), 'errorClass' => get_class($exception)];
     }
     if ($exception->getPrevious() !== NULL) {
         $json['previous'] = $exception->getPrevious()->getMessage();
     }
     $json['stacktrace'] = explode("\n", $exception->getTraceAsString());
     $statusMessage = Response::getStatusMessageByCode($statusCode);
     if (!headers_sent()) {
         header(sprintf('HTTP/1.1 %s %s', $statusCode, $statusMessage));
         header('Content-Type: application/json');
     }
     print json_encode($json);
 }
 /**
  * @param \Exception $exception
  * @param array      $data
  * 
  * @return JsonResponse
  */
 protected function createFailJsonResponse(\Exception $exception, $data)
 {
     if (!$this->isProdEnv()) {
         return new JsonResponse(['success' => 'nok', 'error' => $exception->getMessage(), 'trace' => $exception->getTrace(), 'data' => $data]);
     }
     return new JsonResponse(['success' => 'nok', 'error' => $exception->getMessage()]);
 }
Example #11
0
 /**
  * Show exception screen
  *
  * @param \Exception $exception
  */
 public function showException(\Exception $exception)
 {
     @ob_end_clean();
     $msg = sprintf("%s\nFile: %s\nLine: %d\nTrace:\n%s", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
     \Kalibri::logger()->add(Logger::L_EXCEPTION, $msg);
     $viewName = \Kalibri::config()->get('error.view.exception');
     if ($viewName) {
         $view = new \Kalibri\View($viewName);
         $view->ex = $exception;
         $str = '';
         $file = \fopen($exception->getFile(), 'r');
         for ($i = 0; $i < $exception->getLine() - 16; $i++) {
             \fgets($file);
         }
         for ($i = 0; $i < 20; $i++) {
             $str .= \fgets($file);
         }
         $view->code = Highlight::php($str, true, 1, $exception->getLine());
         if ($view->isExists()) {
             $view->render();
         } else {
             // Fallback to show any message in case if exception view not found or not set
             echo "<h1>Exception</h1><p>{$exception->getMessage()}</p>";
         }
     }
     exit;
 }
 public static function exception(\Exception $e)
 {
     // echo get_class($e).'<br />';
     if ($e->getCode() !== 0 && !(error_reporting() & $e->getCode())) {
         // This error code is not included in error_reporting
         return;
     }
     switch ($e->getCode()) {
         case E_USER_ERROR:
             echo '<b>USER ERROR</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             echo '  Fatal error on line ' . $e->getLine() . ' in file ' . $e->getFile();
             echo ', PHP ' . PHP_VERSION . ' (' . PHP_OS . ')<br />\\n';
             echo 'Aborting...<br />\\n';
             exit(1);
             break;
         case E_USER_WARNING:
             echo '<b>WARNING</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             break;
         case E_USER_NOTICE:
             echo '<b>NOTICE</b> ' . $e->getCode() . ' ' . $e->getMessage() . '<br />\\n';
             break;
         default:
             self::printError($e);
             break;
     }
     /* Don't execute PHP internal error handler */
     return true;
 }
Example #13
0
 public function onKernelResponse(FilterResponseEvent $event)
 {
     $debug = $this->container->getParameter('rest.config')['debug'];
     $arr = $event->getRequest()->headers->get("accept");
     if (!is_array($arr)) {
         $arr = array($arr);
     }
     if (is_array($arr) && (in_array("text/html", $arr) || in_array("*/*", $arr))) {
         return;
     }
     $response = $event->getResponse();
     if (in_array($response->headers->get("content-type"), $arr)) {
         return;
     }
     $error = $response->isServerError() || $event->getResponse()->isClientError();
     if ($error && self::$exception != null) {
         $result = array();
         $result["status"] = $response->getStatusCode();
         if (self::$exception != null) {
             $result["message"] = self::$exception->getMessage();
             if ($debug) {
                 $result["stacktrace"] = self::$exception->getTraceAsString();
             }
         } else {
             $result["message"] = "unknown";
             if ($debug) {
                 $result["stacktrace"] = "";
             }
         }
         $classParser = $this->container->get("rest.internal_class_parser");
         $content = $classParser->serializeObject($result, true);
         $response->setContent($content["result"]);
         $response->headers->add(array("content-type" => $content["type"]));
     }
 }
 public function handleException(Exception $exception, $shutdown = false)
 {
     $this->_exception = $exception;
     $email = new CakeEmail('error');
     $prefix = Configure::read('ExceptionNotifier.prefix');
     $from = $email->from();
     if (empty($from)) {
         $email->from('*****@*****.**', 'Exception Notifier');
     }
     $subject = $email->subject();
     if (empty($subject)) {
         $email->subject($prefix . '[' . date('Ymd H:i:s') . '][' . $this->_getSeverityAsString() . '][' . ExceptionText::getUrl() . '] ' . $exception->getMessage());
     }
     if ($this->useSmtp) {
         $email->transport('Smtp');
         $email->config($this->smtpParams);
     }
     $text = ExceptionText::getText($exception->getMessage(), $exception->getFile(), $exception->getLine());
     $email->send($text);
     // return Exception.handler
     if ($shutdown || !$this->_exception instanceof ErrorException) {
         $config = Configure::read('Exception');
         $handler = $config['handler'];
         if (is_string($handler)) {
             call_user_func($handler, $exception);
         } elseif (is_array($handler)) {
             call_user_func_array($handler, $exception);
         }
     }
 }
Example #15
0
 /**
  * Sends a response for the given Exception.
  *
  * If you have the Symfony HttpFoundation component installed,
  * this method will use it to create and send the response. If not,
  * it will fallback to plain PHP functions.
  *
  * @param \Exception $exception An \Exception instance
  *
  * @see sendPhpResponse
  * @see createResponse
  */
 public function handle(\Exception $exception)
 {
     if ($this->logger !== null) {
         $this->logger->error($exception->getMessage());
     }
     if ($this->logger_trace !== null) {
         $string = $exception->getMessage() . "\r\n";
         foreach ($exception->getTrace() as $trace) {
             $string .= '    ';
             if (isset($trace['file'])) {
                 $string .= 'at ' . $trace['file'] . '(' . $trace['line'] . ') ';
             }
             if (isset($trace['class'])) {
                 $string .= 'in ' . $trace['class'] . $trace['type'];
             }
             if (isset($trace['function'])) {
                 $string .= $trace['function'] . '(' . $this->stringify($trace['args']) . ')';
             }
             $string .= "\r\n";
         }
         $this->logger_trace->error($string);
     }
     if (class_exists('Symfony\\Component\\HttpFoundation\\Response')) {
         $this->createResponse($exception)->send();
     } else {
         $this->sendPhpResponse($exception);
     }
 }
Example #16
0
 /**
  * @param \Exception $objEx
  */
 public function push(\Exception $objEx)
 {
     $this->errorStackTraces[] = ['code' => $objEx->getCode(), 'file' => $objEx->getFile(), 'line' => $objEx->getLine(), 'msg' => $objEx->getMessage(), 'string' => $objEx->getTraceAsString()];
     if ($this->versionType === 'dev') {
         print sprintf('Exception in %s, line %s with message %s', $objEx->getFile(), $objEx->getLine(), $objEx->getMessage());
     }
 }
Example #17
0
 public function action_show()
 {
     $status = $this->error instanceof HttpException ? $this->error->getStatus() : '500 Internal Server Error';
     $data = $this->error instanceof HttpException ? $this->error->getData() : [];
     $this->response->add_header('HTTP/1.1 ' . $status);
     $this->response->body = array_merge(['message' => $this->error->getMessage(), 'code' => $this->error->getCode()], $data);
 }
Example #18
0
 public function displayException(Exception $e)
 {
     $owebsites = new OnpubWebsites($this->pdo);
     try {
         $website = $owebsites->get($this->websiteID);
     } catch (PDOException $e) {
         throw $e;
     }
     $widget = new OnpubWidgetHeader("Upload Images", ONPUBAPI_SCHEMA_VERSION, $this->pdo);
     $widget->display();
     switch ($e->getCode()) {
         case ONPUBGUI_ERROR_MOVE_UPLOADED_FILE:
             en('<span class="onpub-error">' . $e->getMessage() . '</span>', 1, 2);
             en('Make sure the Image Uploads Directory of <a href="index.php?onpub=EditWebsite&amp;websiteID=' . $this->websiteID . '">' . $website->name . '</a> is a valid path and is writable by the web server account.');
             break;
         case ONPUBGUI_ERROR_IMAGE_EXISTS:
             en('<form id="onpub-form" action="index.php" method="post">');
             en('<div>');
             en('<p class="onpub-error"><i>' . $e->getMessage() . '</i> already exists.</p>');
             en('<p>Would you like to overwrite the existing image file?</p>');
             en('<p><input type="submit" id="keepImage" value="Keep Existing File"> <input type="submit" id="overwriteImage" value="Overwrite Existing File"></p>');
             en('<p><input type="hidden" name="websiteID" value="' . $this->websiteID . '"><p>');
             en('<p><input type="hidden" name="overwrite" value="0"><p>');
             en('<p><input type="hidden" name="overwriteFileName" value="' . $e->getMessage() . '"><p>');
             en('<p><input type="hidden" name="onpub" value="UploadImagesProcess"><p>');
             en('</div>');
             en('</form>');
             break;
         default:
             en('<span class="onpub-error">' . $e->getMessage() . '</span>');
             break;
     }
     $widget = new OnpubWidgetFooter();
     $widget->display();
 }
Example #19
0
 /**
  * @return string
  */
 public function getExceptionMessage()
 {
     if (!$this->exception) {
         return '';
     }
     return $this->exception->getMessage();
 }
Example #20
0
 /**
  * Function must be public to call on caused exceptions
  * 
  * @param  array
  * @return string
  */
 function getCauseMessage(&$causes)
 {
     $trace = $this->getTrace();
     $cause = array('class' => get_class($this), 'message' => $this->getMessage(), 'file' => 'unknown', 'line' => 'unknown');
     if (isset($trace[0])) {
         if (isset($trace[0]['file'])) {
             $cause['file'] = $trace[0]['file'];
             $cause['line'] = $trace[0]['line'];
         }
     }
     $causes[] = $cause;
     if ($this->cause instanceof Exception) {
         $this->cause->getCauseMessage($causes);
     } elseif ($this->cause instanceof Exception) {
         $causes[] = array('class' => get_class($this->cause), 'message' => $this->cause->getMessage(), 'file' => $this->cause->getFile(), 'line' => $this->cause->getLine());
     }
     if (is_array($this->cause)) {
         foreach ($this->cause as $cause) {
             if ($cause instanceof Exception || $cause instanceof Exception) {
                 $cause->getCauseMessage($causes);
             } elseif ($cause instanceof Exception) {
                 $causes[] = array('class' => get_class($cause), 'message' => $cause->getMessage(), 'file' => $cause->getFile(), 'line' => $cause->getLine());
             } elseif (is_array($cause) && isset($cause['message'])) {
                 // PEAR_ErrorStack warning
                 $causes[] = array('class' => $cause['package'], 'message' => $cause['message'], 'file' => isset($cause['context']['file']) ? $cause['context']['file'] : 'unknown', 'line' => isset($cause['context']['line']) ? $cause['context']['line'] : 'unknown');
             } else {
                 $causes[] = array('class' => null, 'message' => $cause, 'file' => null, 'line' => null);
             }
         }
     }
 }
Example #21
0
 /**
  * Resolve user by identity
  *
  * @param  string      $identity
  * @param  string|null $realm
  * @param  string|null $password
  * @return \Zend\Authentication\Result
  * @throws \RuntimeException if cannot read passwords file
  */
 public function resolve($identity, $realm = null, $password = null)
 {
     set_error_handler([$this, 'handleError'], E_WARNING);
     $fp = fopen($this->file, 'r');
     restore_error_handler();
     if (!$fp) {
         throw new \RuntimeException('Unable to open password file: ' . $this->file . ' reason ' . $this->error->getMessage());
     }
     $matchedHash = null;
     while (($line = fgetcsv($fp, 512, ':')) !== false) {
         if ($line[0] !== $identity) {
             continue;
         }
         if (isset($line[2])) {
             if ($line[1] === $realm) {
                 $matchedHash = $line[2];
                 break;
             }
             continue;
         }
         $matchedHash = $line[1];
         break;
     }
     fclose($fp);
     if (empty($matchedHash)) {
         return Result::failureIdentityNotFound();
     }
     return Result::success([new User($identity, $matchedHash, $this->roles)]);
 }
 private function getMessage(\Exception $exception)
 {
     if ($exception instanceof \ErrorException) {
         return ErrorHandler::getErrNoString($exception->getSeverity()) . ' - ' . $exception->getMessage();
     }
     return $exception->getMessage();
 }
Example #23
0
 /**
  * Handle exception
  *
  * @param \Exception $e
  * @return void
  */
 protected function handleException($e)
 {
     $needToMaskDisplayMessage = !$e instanceof \Magento\Framework\Exception\LocalizedException && $this->appState->getMode() != State::MODE_DEVELOPER;
     $displayMessage = $needToMaskDisplayMessage ? (string) new \Magento\Framework\Phrase('An error occurred while processing your request') : $e->getMessage();
     $this->messageManager->addError($displayMessage);
     $this->logger->critical($e->getMessage());
 }
 /**
  * After action.
  *
  * @param \CInlineAction $action Action from controller
  *
  * @return \Docolight\Http\Response
  */
 public function afterAction($action)
 {
     parent::afterAction($action);
     // Basic data template
     $statusCode = 200;
     $data = array('status' => $statusCode, 'message' => 'Success', 'value' => $this->data);
     // Let's find an error
     if ($this->error instanceof Exception) {
         // throw $this->error;
         // Basic data template for an exception
         $statusCode = 500;
         $data = ['status' => $statusCode, 'message' => 'Error', 'value' => ['code' => $this->error->getCode(), 'message' => $this->error->getMessage()]];
         // If exception code is an HTTP resoponse code
         if ($message = Response::getMessageForCode($this->error->getCode())) {
             $statusCode = $this->error->getCode();
             $data['status'] = $statusCode;
             $data['message'] = preg_replace('/^\\d+ /', '', $message);
         } else {
             if (YII_DEBUG) {
                 $data['value']['stack_trace'] = $this->error->getTrace();
             }
         }
     } elseif ($this->data instanceof Response) {
         return $this->data->send();
     }
     return response('json', $statusCode, collect($data), $this->headers)->send();
 }
Example #25
0
 public static function exceptionHandler(\Exception $e)
 {
     $fullTrace = $e->getTrace();
     if (is_callable(array($e, 'postAction'))) {
         $e->postAction($e->getMessage(), $e->getCode());
     }
     if (!DC::getProjectConfig('devMode')) {
         DC::getLogger()->add('Exception: ' . $e->getMessage(), 'exception');
         die;
     }
     $content = '<div style="font-size: 13px; font-family: Consolas, Menlo, Monaco, monospace;white-space: pre-wrap;">';
     $htmlTrace = "<b>\nLast arguments(" . count($fullTrace[0]['args']) . "):</b>\n" . dumpAsString($fullTrace[0]['args']) . "<b>\n\nCall stack:</b>\n<table style='font-size: 13px;'>";
     foreach ($fullTrace as $item) {
         $info = self::compileShortCallee($item);
         $htmlTrace .= '<tr><td style="color:#666;padding-right:10px;">' . $info['file'] . '</td><td>' . $info['call'] . '</td></tr>';
     }
     $htmlTrace .= '</table>';
     $content .= '<div style="background:#c00;color:white;font-weight:bold;padding:5px;margin-bottom: 5px; ">' . $e->getMessage() . '</div>';
     $content .= $htmlTrace;
     $content .= '</div>';
     if (DC::getRouter()->getExecutionMode() == Request::MODE_CONSOLE) {
         $content = strip_tags(str_replace('</td><td>', "\n", $content)) . "\n";
     }
     echo $content;
     die;
 }
Example #26
0
 /**
  * @param \Exception $e
  *
  * @return WebhookResponse
  */
 public static function fromException(\Exception $e)
 {
     if ($e instanceof XsollaWebhookException) {
         return static::fromErrorCode($e->getXsollaErrorCode(), $e->getMessage(), $e->getHttpStatusCode());
     } else {
         return static::fromErrorCode('FATAL_ERROR', $e->getMessage());
     }
 }
 /**
  * Handles an Exception thrown while rendering TypoScript
  *
  * @param string $typoScriptPath path causing the exception
  * @param \Exception $exception exception to handle
  * @param integer $referenceCode
  * @return string
  */
 protected function handle($typoScriptPath, \Exception $exception, $referenceCode)
 {
     if (isset($referenceCode)) {
         return sprintf('Exception while rendering %s: %s (%s)', $this->formatScriptPath($typoScriptPath, "\n\t", false), $exception->getMessage(), $referenceCode);
     } else {
         return sprintf('Exception while rendering %s: %s', $this->formatScriptPath($typoScriptPath, "\n\t", false), $exception->getMessage());
     }
 }
Example #28
0
 public function __invoke(Request $request, Response $response, \Exception $exception)
 {
     $this->logger->critical($exception->getMessage());
     $status = $exception->getCode() ?: 500;
     $data = ["status" => "error", "message" => $exception->getMessage()];
     $body = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
     return $response->withStatus($status)->withHeader("Content-type", "application/json")->write($body);
 }
 /**
  * @param \Exception $e
  * @param $file
  * @throws InvalidTemplateException
  */
 public static function throwError($e, $file)
 {
     if (strpos($e->getMessage(), 'Undefined index') !== false || strpos($e->getMessage(), 'Unable to load template file') !== false) {
         throw new self($e->getMessage() . " at file {$file}", self::$UNDEFINED_INDEX);
     } else {
         throw new self($e->getTraceAsString(), self::$OTHERS);
     }
 }
 public function __invoke(Request $request, Response $response, \Exception $exception)
 {
     // Log the message
     $this->logger->critical($exception->getMessage());
     // create a JSON error string for the Response body
     $body = json_encode(['error' => $exception->getMessage(), 'code' => $exception->getCode()], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
     return $response->withStatus(500)->withHeader('Content-type', 'application/json')->write($body);
 }