diff --git a/src/Exception/Handler.php b/src/Exception/Handler.php index ba549e2..ccfd83f 100644 --- a/src/Exception/Handler.php +++ b/src/Exception/Handler.php @@ -58,7 +58,15 @@ public function __construct(ClientException $exception) $errorCode = isset($error['ResponseCode']) ? $error['ResponseCode'] : null; $errorType = isset($error['type']) ? $error['type'] : null; $message = isset($error['Message']) ? $error['Message'] : null; - $missingParameter = isset($error['Errors']) ? $this->getMissingParameters($error['Errors']) : null; + + /** + * This is depreciated and will be removed in version 2. + * + * Hubtel changed the 'Error' key to 'Errors' + */ + isset($error['Errors']) ? ($error['Error'] = $error['Errors']) : null; + + $missingParameter = isset($error['Error']) ? $this->getMissingParameters($error['Error']) : null; $exception = $this->handleException( $message, $statusCode, $errorType, $errorCode, $missingParameter, $rawOutput diff --git a/tests/Unit/Exception/HandlerTest.php b/tests/Unit/Exception/HandlerTest.php index 6676034..de5de98 100644 --- a/tests/Unit/Exception/HandlerTest.php +++ b/tests/Unit/Exception/HandlerTest.php @@ -165,4 +165,35 @@ public function test_4010_missenParameter_request_response() throw $e; } } + + /** + * @depreciated + * This has been depreciated and will be removed in v2 + * @return + */ + public function test_4010_missenParameter_request_response_backward_compatibility() + { + $this->expectException(MissingParameterException::class); + + try { + + $this->useResponse(400, json_encode([ + 'ResponseCode' => 4010, + 'Error' => [ + array('Field' => 'Some Field'), + array('Field' => 'Other Field'), + ], + ])); + } catch (MissingParameterException $e) { + + $this->assertSame(4010, $e->getErrorCode()); + $this->arrayHasKey('ResponseCode', $e->getRawOutput()); + $this->assertContains('MissingParameter', $e->getErrorType()); + $this->assertContains('Some Field', $e->getMissingParameter()); + $this->assertContains('Other Field', $e->getMissingParameter()); + + throw $e; + } + } + }