You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
881 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Exception\Handler;
  3. use App\Exception\SsdbException;
  4. use Hyperf\ExceptionHandler\ExceptionHandler;
  5. use Psr\Http\Message\ResponseInterface;
  6. use Throwable;
  7. use App\Constants\ErrorCode;
  8. use Hyperf\HttpMessage\Stream\SwooleStream;
  9. class SsdbExceptionHandler extends ExceptionHandler
  10. {
  11. public function handle(Throwable $throwable, ResponseInterface $response)
  12. {
  13. $this->stopPropagation();
  14. $content = json_encode([
  15. "status" => 'error',
  16. "code" => $throwable->getCode(),
  17. "result" => [],
  18. "message" => $throwable->getMessage()
  19. ]);
  20. return $response->withHeader('Content-Type', 'application/json')->withBody(new SwooleStream($content));
  21. }
  22. public function isValid(Throwable $throwable): bool
  23. {
  24. return $throwable instanceof SsdbException;
  25. }
  26. }