Skip to content

Commit

Permalink
Handle developer_message in preview responses (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe authored May 25, 2023
1 parent acaaeb4 commit 40d6a38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function handleErrorResponse($rbody, $rcode, $rheaders, $resp)
*/
private static function _specificAPIError($rbody, $rcode, $rheaders, $resp, $errorData)
{
$msg = isset($errorData['message']) ? $errorData['message'] : null;
$msg = isset($errorData['message']) ? $errorData['message'] : (isset($errorData['developer_message']) ? $errorData['developer_message'] : null);
$param = isset($errorData['param']) ? $errorData['param'] : null;
$code = isset($errorData['code']) ? $errorData['code'] : null;
$type = isset($errorData['type']) ? $errorData['type'] : null;
Expand Down
27 changes: 27 additions & 0 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,33 @@ public function testRaisesOAuthUnsupportedResponseTypeError()
}
}

public function testHandlesErrorWithDeveloperMessage()
{
$this->stubRequest(
'POST',
'/v1/charges',
[],
null,
false,
[
'error' => [
'developer_message' => 'Unacceptable',
],
],
400
);

try {
Charge::create();
static::fail('Did not raise error');
} catch (Exception\InvalidRequestException $e) {
static::assertSame(400, $e->getHttpStatus());
static::assertSame('Unacceptable', $e->getMessage());
} catch (\Exception $e) {
static::fail('Unexpected exception: ' . \get_class($e));
}
}

public function testHeaderStripeVersionGlobal()
{
Stripe::setApiVersion('2222-22-22');
Expand Down

0 comments on commit 40d6a38

Please sign in to comment.