/** * Handle custom ajax response * * @param [type] $request [description] * @param [type] $e [description] * * @return [type] [description] */ protected function handleAjaxException($request, $e) { $response = null; $responseContents = []; // Laravel default validation if ($e instanceof LaravelValidationException && $e->getResponse()) { $errors = $e->validator->messages(); $fields = []; foreach ($errors->getMessages() as $field => $messages) { $fields[$field] = $messages; } $message = $errors->first(); return $this->makeAjaxResponseContent($fields, $message); // Our custom, more simple Validation exception } else { if ($e instanceof ValidationException) { return $this->makeAjaxResponseContent($e->getFields(), $e->getMessage()); // Ajax error message } else { if ($e instanceof AjaxException) { $responseContents = array_merge_recursive($responseContents, $e->getContents()); $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $responseContents['result']; // Smart error code $response = response()->json($responseContents, 406); // Runtime Errors } else { if ($e instanceof \ErrorException) { $message = env('APP_DEBUG', false) ? ajax_dump($e) : 'Whoops, we encountered an error.'; $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $message; $response = response()->json($responseContents, 406); // Catch all } else { $message = env('APP_DEBUG', false) ? ajax_dump($e) : 'Whoops, we encountered an error.'; $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $message; $response = response()->json($responseContents, 406); } } } } return $response; }
/** * 输出异常 * @param [type] $exception [description] * @param integer $http_code [description] * @return [type] [description] */ public static function error($exception, $http_code = 500) { $result = ["message" => $exception->getMessage(), "error_code" => $exception->getCode()]; return self::json($result, $http_code); }
/** * Custom exception handler * * @param [type] $e [description] * @return [type] [description] */ function exception_handler($e) { echo "\n<style>\n\t.dmnErr{\n\t\tpadding : 100px;\n\t\tfont-family : Helvetica, Arial, sans-serif;\n\t\tline-height : 1.8em;\n\t\tcolor: #333;\n\t}\n\t.damnMsg{\n\t\tfont-size: 2em;\n\t\tline-height: 2.2em;\n\t\tfont-weight : bold;\n\n\t}\n</style>\n\t"; echo '<div class="dmnErr">'; echo '<div class="damnMsg">' . $e->getMessage() . "</div>"; echo '<div class="damnFl">File : ' . $e->getFile() . "</div>"; echo '<div class="damnLn"> Line : ' . $e->getLine() . "</div>"; echo '<pre class="damnTrc">'; echo "<h2>Trace:</h2>" . $e->getTraceAsString() . "<br>"; echo "</pre>"; echo '</div>'; }
/** * [placeholder description] * * @param [type] $exception [placeholder] * @return [type] */ public static function formatException($exception) { if ($exception instanceof MOJOInstallFailedException) { $situation = $exception->getSituation(); } elseif (self::$step) { $situation = self::$step; } else { $situation = $exception->getFile() . ':' . $exception->getLine(); } if ($exception instanceof MOJOContinueException) { return array('status' => 'continue', 'continue' => true, 'situation' => $situation, 'logs' => self::$logs, 'softFailures' => self::$softFailures); } return array('status' => 'exception', 'version' => phpversion(), 'situation' => $situation, 'step' => self::$step ? self::$step : 'other', 'message' => $exception->getMessage(), 'class' => get_class($exception), 'trace' => $exception->getTraceAsString(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'server' => $_SERVER, 'post' => $_POST, 'get' => $_GET, 'softFailures' => self::$softFailures, 'logs' => self::$logs, 'ini' => ini_get_all(), 'extensions' => get_loaded_extensions()); }
/** * {@inheritdoc} */ public function getReasonPhrase() { return $this->status->getMessage(); }
/** * [throwError description] * @param [type] $error [description] * @return [type] [description] */ public function throwError($error) { $this->out('Error #' . $error->getCode() . ' - ' . JText::_($error->getMessage())); die; }