-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/exception factory #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments
src/Exception/ApiException.php
Outdated
@@ -3,6 +3,35 @@ | |||
|
|||
/** | |||
*/ | |||
class ApiException extends BunqException | |||
class ApiException extends \Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us please do use Exception;
and then Exception
with no preceding \
:)
src/Exception/ExceptionFactory.php
Outdated
* @param string $message | ||
* @param array $args | ||
* | ||
* @return BadRequestException|ForbiddenException|MethodNotAllowedException|NotFoundException|PleaseContactBunqException|ToManyRequestsException|UnauthorizedException|UnknownApiErrorException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ApiException
would be good :P
|
||
/** | ||
*/ | ||
class ToManyRequestsException extends ApiException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One o
refuged it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG this is in all the SDK's 😁 🙈
src/Exception/ApiException.php
Outdated
* | ||
* @param int $responseCode | ||
*/ | ||
public function __construct($message, $args = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add strict types for arguments (PHP 7.0 style) and doc block params. Also, why are we using $args
? Is it necessary here? If so, please add a comment explaining this to the constructor header.
src/Exception/ApiException.php
Outdated
/** | ||
* @return int | ||
*/ | ||
public function getResponseCode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PHP 7.0 strict response type (: int
)
src/Exception/ExceptionFactory.php
Outdated
* | ||
* @return BadRequestException|ForbiddenException|MethodNotAllowedException|NotFoundException|PleaseContactBunqException|ToManyRequestsException|UnauthorizedException|UnknownApiErrorException | ||
*/ | ||
public static function createExceptionForResponse($message, $args = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question: do we need args here?
Also please add strict param types and the response type :)
@@ -60,15 +61,15 @@ public function execute(ResponseInterface $response) | |||
$errorDescriptions[] = $error[self::FIELD_ERROR_DESCRIPTION]; | |||
} | |||
|
|||
throw new ApiException( | |||
throw ExceptionFactory::createExceptionForResponse( | |||
self::ERROR_FROM_JSON, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it is not yours, but please make the interface of createExceptionForResponse
consistent with that in all the other SDKs if possible :)
self::ERROR_FROM_JSON, | ||
[ | ||
$response->getStatusCode(), | ||
implode(self::SEPERATOR_ERROR, $errorDescriptions), | ||
] | ||
); | ||
} else { | ||
throw new ApiException( | ||
throw ExceptionFactory::createExceptionForResponse( | ||
self::ERROR_UNKNOWN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please make error handling here consistent with what we have in e.g. Python :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments :D
src/Exception/ApiException.php
Outdated
private $responseCode; | ||
|
||
/** | ||
* ApiException constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment can go :)
src/Exception/ApiException.php
Outdated
* | ||
* @param int $responseCode | ||
*/ | ||
public function __construct($message, $responseCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add strict types and docs for both parameters!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crap, I’m really getting old indeed xD
src/Exception/BunqException.php
Outdated
*/ | ||
public function __construct($message, $args = []) | ||
public function __construct($message, $responseCode = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add strict types for both parameters; Also $responseCode
shouldn't be equal to an array I believe :D
src/Exception/ExceptionFactory.php
Outdated
const INDEX_FIRST = 0; | ||
|
||
/** | ||
* @param array $messages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the strict type here :)
src/Exception/ExceptionFactory.php
Outdated
* | ||
* @return ApiException | ||
*/ | ||
public static function createExceptionForResponse($messages, $responseCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tyyypes (both params and return ones)
src/Http/ApiClient.php
Outdated
@@ -188,7 +188,7 @@ private function initializeHttpClient() | |||
self::OPTION_HANDLER => $middleware, | |||
self::OPTION_VERIFY => true, | |||
self::OPTION_CURL => [ | |||
CURLOPT_PINNEDPUBLICKEY => $this->determinePinnedServerPublicKey(), | |||
//CURLOPT_PINNEDPUBLICKEY => $this->determinePinnedServerPublicKey(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wut? Why is it commented out? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shit yea haha, m y curl doesn’t work neither and didn’t fix it 😁. Therefore I must comment this line out for the sdk to work. Obviously forgot to revert it.
@dnl-blkv please 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is looking good, but please add the same changes as in C# to the text. Would be the best if you do so after C#, once we have the C# part merged and consolidated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment, and also please do add context file deletion after session deletion :)
src/Exception/EXCEPTION.md
Outdated
* @param int $responseCode | ||
*/ | ||
public function __construct(string $message, int $responseCode) | ||
{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make it clear that some code is hidden here :)
@dnl-blkv all yours 🎖 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few styling comments... :D
src/Exception/EXCEPTION.md
Outdated
## Exceptions | ||
When you make a request via the SDK, there is a chance of request failing | ||
due to various reasons. When such a failure happens, an exception | ||
corresponding to the error occurred is raised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exceptions are thrown in PHP, not raised! :)
src/Exception/EXCEPTION.md
Outdated
corresponding to the error occurred is raised. | ||
|
||
|
||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these ----
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes a it more beautiful :P Its like a paragraph separator. View it as an actual markdown and you shall see 😁
src/Exception/EXCEPTION.md
Outdated
} | ||
``` | ||
The `Exception` class which is being extended has an `getMessage()` method which is `final` and therefore cannot be | ||
overwritten. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"overridden" please :P
src/Exception/EXCEPTION.md
Outdated
//Make a call that might fail | ||
$apiContext = ApiContext::create(BunqEnumApiEnvironmentType::SANDBOX(), API_KEY, DEVICE_DESCRIPTION); | ||
} catch (BadRequestException $error){ | ||
//Do something if exception is thrown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a minor thing, but here and in all the inline comments (// Comment
) please make sure there is space between //
and the first letter!
@@ -31,6 +36,6 @@ public function testDeleteSession() | |||
*/ | |||
public static function tearDownAfterClass() | |||
{ | |||
static::ensureApiContextValid(); | |||
unlink(static::FILENAME_CONTEXT_CONFIG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I must have missed it at some earlier point. Let us please use self::
for constants :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple more :P
src/Exception/EXCEPTION.md
Outdated
*/ | ||
public function __construct(string $message, int $responseCode) | ||
{ | ||
//Some hidden code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after //
please! :)
src/Exception/EXCEPTION.md
Outdated
const DEVICE_DESCRIPTION = 'This will cause BadRequestException to be thrown.'; | ||
|
||
try{ | ||
//Make a call that might fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after //
please! :)
@dnl-blkv @andrederoos new release? 😄 |
@DennisSnijder yep, planned for tomorrow :) |
@dnl-blkv Awesome! thanks 👍 |
|
||
$errorDescriptions = []; | ||
if ($responseBodyInJson != false){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OGKevin !==
. lets not fall in the php-weak-typing-trap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh 🙈 good 👁 !
#49
Exception factory review
Explain exceptions in a .md file
Final review