Skip to content
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

Merged
merged 20 commits into from
Oct 10, 2017
Merged

Feature/exception factory #50

merged 20 commits into from
Oct 10, 2017

Conversation

OGKevin
Copy link
Contributor

@OGKevin OGKevin commented Sep 21, 2017

#49

  • Exception factory review

  • Explain exceptions in a .md file

  • Final review

Copy link
Contributor

@dnl-blkv dnl-blkv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments

@@ -3,6 +3,35 @@

/**
*/
class ApiException extends BunqException
class ApiException extends \Exception
Copy link
Contributor

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 \ :)

* @param string $message
* @param array $args
*
* @return BadRequestException|ForbiddenException|MethodNotAllowedException|NotFoundException|PleaseContactBunqException|ToManyRequestsException|UnauthorizedException|UnknownApiErrorException
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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 😁 🙈

*
* @param int $responseCode
*/
public function __construct($message, $args = [])
Copy link
Contributor

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.

/**
* @return int
*/
public function getResponseCode()
Copy link
Contributor

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)

*
* @return BadRequestException|ForbiddenException|MethodNotAllowedException|NotFoundException|PleaseContactBunqException|ToManyRequestsException|UnauthorizedException|UnknownApiErrorException
*/
public static function createExceptionForResponse($message, $args = [])
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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 :)

Copy link
Contributor

@dnl-blkv dnl-blkv left a 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

private $responseCode;

/**
* ApiException constructor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can go :)

*
* @param int $responseCode
*/
public function __construct($message, $responseCode)
Copy link
Contributor

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!

Copy link
Contributor Author

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

*/
public function __construct($message, $args = [])
public function __construct($message, $responseCode = [])
Copy link
Contributor

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

const INDEX_FIRST = 0;

/**
* @param array $messages
Copy link
Contributor

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 :)

*
* @return ApiException
*/
public static function createExceptionForResponse($messages, $responseCode)
Copy link
Contributor

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)

@@ -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(),
Copy link
Contributor

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

Copy link
Contributor Author

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.

@OGKevin
Copy link
Contributor Author

OGKevin commented Sep 26, 2017

@dnl-blkv please 👀

Copy link
Contributor

@dnl-blkv dnl-blkv left a 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 :)

Copy link
Contributor

@dnl-blkv dnl-blkv left a 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 :)

* @param int $responseCode
*/
public function __construct(string $message, int $responseCode)
{}
Copy link
Contributor

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 :)

@OGKevin
Copy link
Contributor Author

OGKevin commented Oct 7, 2017

@dnl-blkv all yours 🎖

Copy link
Contributor

@dnl-blkv dnl-blkv left a 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

## 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.
Copy link
Contributor

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! :)

corresponding to the error occurred is raised.


----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these ---- ?

Copy link
Contributor Author

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 😁

}
```
The `Exception` class which is being extended has an `getMessage()` method which is `final` and therefore cannot be
overwritten.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"overridden" please :P

//Make a call that might fail
$apiContext = ApiContext::create(BunqEnumApiEnvironmentType::SANDBOX(), API_KEY, DEVICE_DESCRIPTION);
} catch (BadRequestException $error){
//Do something if exception is thrown.
Copy link
Contributor

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);
Copy link
Contributor

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 :)

Copy link
Contributor

@dnl-blkv dnl-blkv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple more :P

*/
public function __construct(string $message, int $responseCode)
{
//Some hidden code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after // please! :)

const DEVICE_DESCRIPTION = 'This will cause BadRequestException to be thrown.';

try{
//Make a call that might fail
Copy link
Contributor

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 dnl-blkv merged commit d724129 into develop Oct 10, 2017
@dnl-blkv dnl-blkv deleted the feature/exception-factory branch October 10, 2017 17:12
@dnl-blkv
Copy link
Contributor

@andrederoos

@DennisSnijder
Copy link
Contributor

@dnl-blkv @andrederoos new release? 😄

@dnl-blkv
Copy link
Contributor

@DennisSnijder yep, planned for tomorrow :)

@DennisSnijder
Copy link
Contributor

@dnl-blkv Awesome! thanks 👍


$errorDescriptions = [];
if ($responseBodyInJson != false){
Copy link
Contributor

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

Copy link
Contributor Author

@OGKevin OGKevin Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh 🙈 good 👁 !

@OGKevin OGKevin mentioned this pull request Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants