异常处理

  1. <?php
  2. use Hyperf\HttpMessage\Stream\SwooleStream;
  3. use Hyperf\Nano\Factory\AppFactory;
  4. require_once __DIR__ . '/vendor/autoload.php';
  5. $app = AppFactory::create();
  6. $app->get('/', function () {
  7. throw new \Exception();
  8. });
  9. $app->addExceptionHandler(function ($throwable, $response) {
  10. return $response->withStatus('418')
  11. ->withBody(new SwooleStream('I\'m a teapot'));
  12. });
  13. $app->run();