*/ namespace App\Exception\Handler; use App\Service\Log; use App\Service\QueueService; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Di\Annotation\Inject; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; use Psr\Http\Message\ResponseInterface; use Throwable; use function Hyperf\Support\env; /** * * Author: cfn */ class DbQueryExceptionHandle extends ExceptionHandler { public function __construct(protected StdoutLoggerInterface $logger) { } /** * Author: cfn * @param Throwable $throwable * @param ResponseInterface $response * @return ResponseInterface */ public function handle(Throwable $throwable, ResponseInterface $response) { return $response->withHeader('Server', 'leapy')->withStatus(500)->withBody(new SwooleStream(json_encode(['code'=>2,'msg'=>"SQL语句存在错误,请联系服务商"]))); } public function isValid(Throwable $throwable): bool { return $throwable instanceof \Hyperf\Database\Exception\QueryException; } }