本文整理汇总了PHP中Exception::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getErrors方法的具体用法?PHP Exception::getErrors怎么用?PHP Exception::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: error
public static function error(\Exception $e)
{
$app = Slim::getInstance();
if ($e instanceof APIException) {
$app->log->addError("API error [{$e->getHTTPCode()}][{$e->getCode()}]: " . print_r(['error' => $e->getErrors()], 1));
$app->halt($e->getHTTPCode(), json_encode(['error' => $e->getErrors()], JSON_FORCE_OBJECT));
} else {
$app->log->addError("API error [500][{$e->getCode()}]: {$e->getMessage()} \n {$e->getTraceAsString()}");
$app->syslog->addError("API error [500][{$e->getCode()}]: {$e->getMessage()} \n {$e->getTraceAsString()}");
if ($app->config('mode') == 'development') {
self::registerWhoops();
$app->whoops->handleException($e);
}
$app->halt(500);
}
}
示例2: renderException
/**
* Renders the exception.
* @param \Exception $exception the exception to be rendered.
*/
protected function renderException($exception)
{
//如果存在未提交的事务,则对事务进行回滚
$transaction = Yii::$app->db->getTransaction();
if ($transaction) {
$transaction->rollback();
}
//对返回内容进行渲染
if (Yii::$app->has('response')) {
$response = Yii::$app->getResponse();
// reset parameters of response to avoid interference with partially created response data
// in case the error occurred while sending the response.
$response->isSent = false;
$response->stream = null;
$response->data = null;
$response->content = null;
} else {
$response = new Response();
}
$useErrorView = $response->format === Response::FORMAT_HTML && !YII_DEBUG;
//如果是用户定义的异常,则需要将异常错误信息抛出,如果是接口类型的并且有model类型的错误
if ($useErrorView) {
if ($this->errorAction !== null) {
$result = Yii::$app->runAction($this->errorAction);
if ($result instanceof Response) {
$result = $result;
} else {
$result->data = $result;
}
} else {
//在没有默认异常处理action的情况下,直接渲染文件
$file = $useErrorView ? $this->errorView : $this->exceptionView;
$responseData = $this->renderFile($file, ['exception' => $exception]);
}
} else {
if ($response->format === Response::FORMAT_JSON || $response->format === Response::FORMAT_XML) {
$response->data = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
if ($exception instanceof LBUserException) {
$response->data['errors'] = $exception->getErrors();
}
} else {
$response->data = $this->convertExceptionToArray($exception);
}
}
//调试状态状态码为500, 非调试状态不抛出异常
if (!YII_DEBUG || $exception instanceof LBUserException) {
$response->setStatusCode(200);
} else {
$response->setStatusCode(500);
}
$response->send();
}