异常分类:
1.由于用户行为导致的异常(没有通过验证器,没查询到结果),通常不需要记录日志,需要向用户返回具体信息
2.服务器自身异常(代码错误,调用外部接口错误),通常记录日志,不向客户端返回具体原因
实现自定义全局异常处理:
建立类库lib,创建exception文件,创建ExceptionHandler.php用于继承Handler类,重写render方法

将v1\Banner.php里返回到客户端的相关信息写成一个类BaseException.php,用于统一描述信息


然后定义一个子类BannerMissException.php用于继承BaseException.php

需要配置

结果报错

不知道为什么报错,明天再看看
网友评论