agilesdesign/exceptum

Laravel 自定义异常处理

v1.0.0-alpha.1 2016-11-29 22:21 UTC

This package is auto-updated.

Last update: 2024-09-22 22:29:21 UTC


README

Laravel 自定义异常处理

安装

通过 composer 包管理器安装

composer require agilesdesign/exceptum

添加到提供者列表
'providers' => [
    Exceptum\Providers\ExceptumServiceProvider::class,
];

用法

创建一个助手

Abettor 在其意图上等同于 App\Exceptions\Handler,但它不是它的扩展。

目前它只支持在 App\Exception\Handlerrender 方法上实现响应

class AuthorizatonExceptionAbettor implements Abettor
{
    public function render($request, Exception $exception)
    {
        // handle exception
    }
}
注册映射

除非Exceptum知道负责抛出异常的助手,否则它会回退到Laravel的App\Exception\Handler类。

要告诉Exceptum有关助手的信息,请在您的 ServiceProvidersregister 方法中注册映射。

public function register()
{
    Exceptum::map(AuthorizationException::class, AuthorizationExceptionAbettor::class);
}