private function createResponse(Request $request, Socket $socket) : \Generator
{
try {
assert(yield from $this->log->log(Log::DEBUG, 'Received request from %s:%d for %s', $socket->getRemoteAddress(), $socket->getRemotePort(), $request->getUri()));
$response = $this->handler->onRequest($request, $socket);
if ($response instanceof \Generator) {
$response = (yield from $response);
} elseif ($response instanceof Awaitable) {
$response = (yield $response);
}
if (!$response instanceof Response) {
throw new InvalidResultError(sprintf('A %s object was not returned from %::onRequest().', Response::class, get_class($this->handler)), $response);
}
} catch (Throwable $exception) {
yield from $this->log->log(Log::ERROR, "Uncaught exception when creating response to a request from %s:%d on %s:%d in file %s on line %d: %s", $socket->getRemoteAddress(), $socket->getRemotePort(), $socket->getLocalAddress(), $socket->getLocalPort(), $exception->getFile(), $exception->getLine(), $exception->getMessage());
$response = (yield from $this->createDefaultErrorResponse(500));
}
return $response;
}