| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | namespace Worldline\Acquiring\Sdk\V1; |
| 6: | |
| 7: | use Worldline\Acquiring\Sdk\CallContext; |
| 8: | use Worldline\Acquiring\Sdk\Domain\DataObject; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | class ExceptionFactory |
| 16: | { |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | public function createException( |
| 25: | int $httpStatusCode, |
| 26: | DataObject $errorObject, |
| 27: | ?CallContext $callContext = null |
| 28: | ): ApiException { |
| 29: | if ($httpStatusCode === 400) { |
| 30: | return new ValidationException($httpStatusCode, $errorObject); |
| 31: | } |
| 32: | if ($httpStatusCode === 403) { |
| 33: | return new AuthorizationException($httpStatusCode, $errorObject); |
| 34: | } |
| 35: | if ($httpStatusCode === 404) { |
| 36: | return new ReferenceException($httpStatusCode, $errorObject); |
| 37: | } |
| 38: | if ($httpStatusCode === 409) { |
| 39: | return new ReferenceException($httpStatusCode, $errorObject); |
| 40: | } |
| 41: | if ($httpStatusCode === 410) { |
| 42: | return new ReferenceException($httpStatusCode, $errorObject); |
| 43: | } |
| 44: | if ($httpStatusCode === 500) { |
| 45: | return new PlatformException($httpStatusCode, $errorObject); |
| 46: | } |
| 47: | if ($httpStatusCode === 502) { |
| 48: | return new PlatformException($httpStatusCode, $errorObject); |
| 49: | } |
| 50: | if ($httpStatusCode === 503) { |
| 51: | return new PlatformException($httpStatusCode, $errorObject); |
| 52: | } |
| 53: | return new ApiException($httpStatusCode, $errorObject); |
| 54: | } |
| 55: | } |
| 56: | |