logger = $logger; } public function handle(Throwable $throwable, ResponseInterface $response) { $this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); $this->logger->error($throwable->getTraceAsString()); $this->stopPropagation(); $content = [ "status" => 'error', "code" => $throwable->getCode(), "result" => [], "message" => $throwable->getMessage() ]; $this->log->event(LogLabel::ERROR_CODE_EXCEPTION, $content); return $response->withHeader('Content-Type', 'application/json') ->withStatus(200) ->withBody(new SwooleStream(json_encode($content))); } public function isValid(Throwable $throwable): bool { return $throwable instanceof ErrorCodeException; } }