# 异常篇
laravel-fast-api 分别在 分别封装了后台和前端以及公共和验证规则的异常处理
- App\Exceptions\Admin\CommonException.php 后台异常处理
- App\Exceptions\Phone\CommonException.php 用户异常处理
- App\Exceptions\Common\CommonException.php 通用异常处理
- App\Exceptions\Common\RuleException.php 表单验证异常处理
TIP
为了方便快速定位异常位置,统一在自定义配置文件处,统一定义异常及事件码.同时为了方便维护,根据业务不同业务逻辑和模块,分开定义异常和事件码
例如
config\custom\laravel-fast-api\admin\code 后台异常错误码 config\custom\laravel-fast-api\admin\event 后台事件码 config\custom\laravel-fast-api\phone\code 用户异常错误码 config\custom\laravel-fast-api\phone\event 用户事件码
# 定义位置
在服务提供者处定义,示例如下:
- 错误码
//后台错误码
//整合
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/code/admin_code.php'),'admin_code'
);
//系统配置
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/code/admin_system_code.php'),'admin_code'
);
//文章
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/code/admin_article_code.php'),'admin_code'
);
//文件
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/code/admin_file_code.php'),'admin_code'
);
- 事件码
//全部
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/event/admin_event.php'),'admin_event'
);
//文章
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/event/admin_article_event.php'),'admin_event'
);
//文件
$this->mergeConfigFrom(
config_path('custom/laravel-fast-api/admin/event/admin_file_event.php'),'admin_event'
);
# 定义方式
示例如下:
- 错误码
'ParamsIsNullError'=>[ 'code'=>10000, 'msg'=>'请求参数为空!','error'=>'ParamsIsNullError'],
- 事件码
//开发者
'AddDeveloper' => [ 'code' => 10000, 'info' => '添加后台开发者','event'=>'AddDeveloper' ],
以上示例只是提供参考,总结来说,就可以自定义位置和名称,名称总共采用admin_,phone_,common_*,rule_*连接的方式来定义
← 事件篇 supervisor篇 →