abstem/rest-handler

Laravel 的 REST 请求自定义异常处理器。

0.0.1 2017-11-14 21:29 UTC

This package is not auto-updated.

Last update: 2024-09-20 02:38:48 UTC


README

Laravel REST 请求异常处理器

如果你需要在自定义异常情况下渲染 JSON 响应,这是一个完美的库。

安装

$ composer require abstem/rest-handler

接下来,更新 App/Exceptions/Handler.php 中的异常处理器基类,从

<?php
namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    //  Your Code here
}

<?php
namespace App\Exceptions;

use Exception;
use Abstem\RestHandler\Exceptions\ExceptionHandler;

class Handler extends ExceptionHandler
{
    protected $handlers = [
        'You\Custom\Exception'  =>  'Your\Custom\Handler',    
    ];
    
    //  Your Code here
}

就这么简单,在 Yourc\Custom\Handler 中你应该接收到一个 handle($request, $exception) 方法