mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
552 stars 191 forks source link

Refactor (Api)Exceptions #338

Closed sandervanhooft closed 5 years ago

sandervanhooft commented 5 years ago

Specifications

Describe the issue

While trying to implement a dedicated Exception for enabling methods (#332, #334), it became clear that the ApiException requires some refactoring.

The current ApiException constructor signature does not allow for easy extension, because not all relevant information is stored on the instance.

I.e. for the EnableMethodException use case, it's necessary to retrieve the dashboard link from the exception, which is available in the response, but not in the exception. All response _links should be available on the ApiException for easy extension.

I'll open a separate PR for this and design a more suitable constructor signature.

sandervanhooft commented 5 years ago

@willemstuursma Can't find anything in the Mollie docs, but are there (plans for?) unique exception codes in the API responses?

This way we could throw an ApiException by default, and define a list of matching handlers to throw a dedicated ApiException child class more easily, without sprinkling the if ... throw logic for this around the client source.

sandervanhooft commented 5 years ago

Closing this for now.