Skip to content

Commit

Permalink
Merge pull request #630 from sandervanhooft/add_plain_exception_message
Browse files Browse the repository at this point in the history
Added ApiException.getPlainMessage
  • Loading branch information
sandervanhooft authored Jul 11, 2022
2 parents 754cc6c + e973ac0 commit 43ae547
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Exceptions/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ApiException extends \Exception
*/
protected $field;

/**
* @var string
*/
protected $plainMessage;

/**
* @var \Psr\Http\Message\RequestInterface|null
*/
Expand Down Expand Up @@ -50,6 +55,8 @@ public function __construct(
$response = null,
$previous = null
) {
$this->plainMessage = $message;

$this->raisedAt = new \DateTimeImmutable();

$formattedRaisedAt = $this->raisedAt->format(DateTime::ISO8601);
Expand Down Expand Up @@ -224,4 +231,14 @@ protected static function parseResponseBody($response)

return $object;
}

/**
* Retrieve the plain exception message.
*
* @return string
*/
public function getPlainMessage()
{
return $this->plainMessage;
}
}
1 change: 1 addition & 0 deletions tests/Mollie/API/Exceptions/ApiExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public function testCanGetRequestBodyIfRequestIsSet()

$this->assertJsonStringEqualsJsonString(/** @lang JSON */'{ "foo": "bar" }', $exception->getRequest()->getBody()->__toString());
$this->assertStringEndsWith('Error executing API call (422: Unprocessable Entity): Can not enable Credit card via the API. Please go to the dashboard to enable this payment method.. Documentation: https://docs.mollie.com/guides/handling-errors. Request body: { "foo": "bar" }', $exception->getMessage());
$this->assertEquals('Error executing API call (422: Unprocessable Entity): Can not enable Credit card via the API. Please go to the dashboard to enable this payment method.', $exception->getPlainMessage());
}
}

0 comments on commit 43ae547

Please sign in to comment.