lakshmaji/exceptions

Laravel 异常处理器

1.0.0 2018-06-10 05:34 UTC

This package is auto-updated.

Last update: 2024-09-08 18:52:55 UTC


README

使用 composer 安装

    composer require lakshmaji/exceptions

服务提供者将自动注册

发布翻译

    php artisan vendor:publish 

自定义异常类

<?php

namespace App;

use Lakshmaji\Exceptions\GenericExceptionType;


/**
 * -----------------------------------------------------------------------------
 *   CustomException for defining exception codes
 * -----------------------------------------------------------------------------
 * Class having methods to define error codes related to DB exceptions.
 *
 * @since    1.0.0
 * @version  1.0.0
 * @author   Lakshmaji 
 */
class CustomException extends GenericExceptionType
{
    // DUPLICATE RECORD
    /**
     * @var array
     */
    public static $DUPLICATE_RECORD = ['error_code' => 12000, 'code' => 400];
    
    // General Error
    /**
     * @var array
     */
    public static $GENERAL_ERROR = ['error_code' => 10001, 'code' => 400];

    
}
// end of class GenericExceptionType
// end of file GenericExceptionType.php

用法

    // In controller
    throw new GenericException(CustomException::$DUPLICATE_ORGANIZATION);

许可协议

MIT