yolo/errors

用于处理yolo错误的包

维护者

详细信息

gitee.com/lushaoming/yolo-errors

v1.0.3 2024-05-11 03:40 UTC

This package is not auto-updated.

Last update: 2024-09-28 05:19:12 UTC


README

yolo微服务框架的错误处理包。

用法

  • 注册错误模块和类型。

    $registry = \Yolo\Errors\ExceptionRegistry::inst();
    $registry->createExceptionRegistry(
      'user.service.com',
      [
          'user' => [
              'index' => Number::createIncreaseCodeIndex(1000000)
          ]
      ]
    );
    
  • 注册一个错误

    $registry->register(
      (new \Yolo\Errors\ResponseError('user', 'user_not_found', 'User not found.'))->setHttpStatus(404)
    );
    
  • 抛出一个新错误

    throw \Yolo\Service\ApiGateway::responseError('user_not_found', [
      'userId' => 123,
    ]);
    

它将抛出一个YoloException,该异常将被框架捕获并处理,然后返回。