As for recommendations states:
A Client MUST NOT treat a well-formed HTTP request or HTTP response as an error condition. For example, response status codes in the 400 and 500 range MUST NOT cause an exception and MUST be returned to the Calling Library as normal.
So basically what we should do is refactor this part:
We should just add 'http_erros` flag on instanciating Guzzle client, and handle all 4xx, 5xx by our selfs.
$this->guzzle = new Guzzle(
'http_errors' => false
Also, we should never ever return exception as an object from API call like this:
catch (Exception $error) {
return $error;
}
So we would return all responses in an array and raise an exception if LogicBoxes response contains Action status strtolower(ERROR).
Since this would be a major change, I propose to release it as V.2.0.0 to not break existing libs
@rytisder You are completely right I will go through it. I really missed returning exception part of our code it is a completely wrong way to handle errors as you mentioned.
Thanks for this great issue. 👍
As for recommendations states:
A Client MUST NOT treat a well-formed HTTP request or HTTP response as an error condition. For example, response status codes in the 400 and 500 range MUST NOT cause an exception and MUST be returned to the Calling Library as normal.
So basically what we should do is refactor this part:
We should just add 'http_erros` flag on instanciating Guzzle client, and handle all 4xx, 5xx by our selfs.
Also, we should never ever return exception as an object from API call like this:
So we would return all responses in an array and raise an exception if LogicBoxes response contains Action status strtolower(
ERROR
). Since this would be a major change, I propose to release it as V.2.0.0 to not break existing libs@see https://www.php-fig.org/psr/psr-18/