idealogica/error-handler

基于Booboo的错误处理器,支持HTML和JSON

1.0.18 2021-11-11 09:36 UTC

This package is auto-updated.

Last update: 2024-09-11 15:29:08 UTC


README

1. 特性

  • 允许基于请求URI设置格式化程序
  • 自动检测CLI模式并使用适当的格式化程序
  • 使用模板自定义错误页面
  • 可以检测不允许显示的异常,并显示通用的“服务器错误”消息,而不是确切的异常信息

2. 安装

composer require idealogica/error-handler:~1.0.0

3. 基本示例

$handler = new ErrorHandler(
    new ServerRequest('GET', new Uri('https://www.server.test/api/endpoint')),
    [
        '/api/.*' => [new JsonFormatter()],
        '.*' => [new HtmlFormatter(ViewFactory::createStringViewFactory())]
    ],
    [
        new CommandLineFormatter()
    ],
    $debugMode,
    InvalidArgumentException::class
);
$handler->register();

4. 许可证

ErrorHandler遵循MIT许可证