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