src/ApiBundle/Api/Util/ExceptionUtil.php

(开头部分) 1015B

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace ApiBundle\Api\Util;

use ApiBundle\Api\Exception\ErrorCode;
use AppBundle\Common\ExceptionPrintingToolkit;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

class ExceptionUtil
{
    public static function getErrorAndHttpCodeFromException(\Exception $exception, $isDebug)
    {
        $error = array();
        if ($exception instanceof HttpExceptionInterface) {
            $error['message'] = $exception->getMessage();
            $error['code'] = $exception->getCode();
            $httpCode = $exception->getStatusCode();
        } else {
            $error['message'] = 'Internal server error';
            $error['code'] = $exception->getCode() ?: ErrorCode::INTERNAL_SERVER_ERROR;
            $httpCode = Response::HTTP_INTERNAL_SERVER_ERROR;
        }

        if ($isDebug) {
            $error['trace'] = ExceptionPrintingToolkit::printTraceAsArray($exception);
        }

        return array($error, $httpCode);
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。