Skip to content

Commit

Permalink
Set backward compatibility for errors validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ovac committed Mar 24, 2018
1 parent 4c1f1d0 commit a2750b2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Exception/Handler.php
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/Unit/Exception/HandlerTest.php
Expand Up @@ -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;
}
}

}

0 comments on commit a2750b2

Please sign in to comment.