binance / binance/binance-connector-php

Why is excptions from Guzzle wrapped in a wya so that it is impossible to get the error messages

Open
#47 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
106
Forks
29
PR merge metrics
No merged PRs in 30d

Description

If an error occure when communicating with Binace and a excpetion is thrown, then a norma try/catch does not really work

From the example - just execute without key/secret

```
$key,
'secret' => $secret,
'baseURL' => 'https://testnet.binance.vision', // set the baseURL to testnet, omit for production site.
'showWeightUsage' => true, // optional, only if you need get order/ip weight usage
]);

try {
$response = $client->newOrder(
'BNBUSDT',
'BUY',
'LIMIT',
[
'quantity' => 1,
'price' => 200,
'timeInForce' => 'GTC',
'newOrderRespType' => 'FULL',
'recvWindow' => 5000,
]
);

} catch (Throwable $e) {
echo $e->getCode()."\r\n";
echo $e->getMessage()."\r\n";
}
```

you will get this:

```
0
```

and then

```

GuzzleHttp\Exception\ClientException: Client error: `POST https://testnet.binance.vision/api/v3/order?quantity=1&price=200&timeInForce=GTC&newOrderRespType=FULL&recvWindow=5000&symbol=BNBUSDT&side=BUY&type=LIMIT×tamp=1747836779253&signature=478f34497d78057f92f5347ec430614316b7953c0ccad579efb356ec9d343bde` resulted in a `401 Unauthorized` response:
{"code":-2014,"msg":"API-key format invalid."}
in /Users/rabol/code/web/zynkto/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
Stack trace:
#0 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run(true)
#5 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /Users/rabol/code/web/zynkto/vendor/guzzlehttp/guzzle/src/Client.php(189): GuzzleHttp\Promise\Promise->wait()
#10 /Users/rabol/code/web/zynkto/vendor/binance/binance-connector-php/src/Binance/APIClient.php(117): GuzzleHttp\Client->request('POST', '/api/v3/order?q...')
#11 /Users/rabol/code/web/zynkto/vendor/binance/binance-connector-php/src/Binance/APIClient.php(111): Binance\APIClient->processRequest('POST', '/api/v3/order', Array)
#12 /Users/rabol/code/web/zynkto/vendor/binance/binance-connector-php/src/Binance/Spot/Trade.php(89): Binance\APIClient->signRequest('POST', '/api/v3/order', Array)
#13 /Users/rabol/code/web/zynkto/test.php(18): Binance\Spot->newOrder('BNBUSDT', 'BUY', 'LIMIT', Array)
#14 {main}

```

normally it would be something like:

```
{"code":-2014,"msg":"API-key format invalid."}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.