Request exception catch

This commit is contained in:
Simon Vieille 2017-10-23 22:42:09 +02:00
parent 152dedd4be
commit 1a3286cadc

View file

@ -1,9 +1,10 @@
<?php
use Phly\Http\Response;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use Phly\Http\ServerRequestFactory;
use Phly\Http\ServerRequest;
use Phly\Http\Response;
require __DIR__.'/vendor/autoload.php';
@ -26,10 +27,10 @@ function doRequest(ServerRequest $request, Client $client)
$headers[$name] = $value[0];
}
$url = sprintf(
'https://bittrex.com/api/v1.1/%s',
ltrim($request->getServerParams()['PATH_INFO'], '/')
);
$serverParams = $request->getServerParams();
$uri = isset($serverParams['PATH_INFO']) ? ltrim($serverParams['PATH_INFO']) : '';
$url = sprintf('https://bittrex.com/api/v1.1/%s', $uri);
unset($headers['host']);
@ -43,10 +44,14 @@ function doRequest(ServerRequest $request, Client $client)
);
}
$apiResponse = doRequest(
ServerRequestFactory::fromGlobals(),
new Client()
);
try {
$apiResponse = doRequest(
ServerRequestFactory::fromGlobals(),
new Client()
);
} catch (ClientException $e) {
$apiResponse = $e->getResponse();
}
send(new Response(
$apiResponse->getBody(),