Skip to content

Commit

Permalink
Show correct Pushover error message in exception
Browse files Browse the repository at this point in the history
  • Loading branch information
casperboone committed Aug 13, 2016
1 parent 81bc0f2 commit 2d57869
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public static function serviceRespondedWithAnError(ResponseInterface $response)

$result = json_decode($response->getBody());

if ($result && isset($result->message)) {
return new static('Pushover responded with an error ('.$statusCode.'): '.$result->message);
if ($result && isset($result->errors)) {
return new static('Pushover responded with an error ('.$statusCode.'): '.implode(', ', $result->errors));
}

return new static('Pushover responded with an error ('.$statusCode.').');
Expand Down
7 changes: 2 additions & 5 deletions tests/PushoverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public function it_throws_an_exception_when_pushover_returns_an_error_with_inval
/** @test */
public function it_throws_an_exception_when_pushover_returns_an_error_with_valid_json()
{
$this->setExpectedException(CouldNotSendNotification::class, 'Pushover responded with an error (400): [error_message]');
$this->setExpectedException(CouldNotSendNotification::class, 'Pushover responded with an error (400): error_message_1, error_message_2');

$guzzleRequest = Mockery::mock(\Psr\Http\Message\RequestInterface::class);
$guzzleResponse = Mockery::mock(\Psr\Http\Message\ResponseInterface::class);
$guzzleResponse->shouldReceive('getStatusCode')->andReturn(400);
$guzzleResponse->shouldReceive('getBody')->andReturn('{"message": "[error_message]"}');
$guzzleResponse->shouldReceive('getBody')->andReturn('{"errors": ["error_message_1", "error_message_2"]}');

$this->guzzleClient->shouldReceive('post')->andThrow(new RequestException(null, $guzzleRequest, $guzzleResponse));

Expand All @@ -91,9 +91,6 @@ public function it_throws_an_exception_when_pushover_returns_nothing()
$this->setExpectedException(CouldNotSendNotification::class, 'The communication with Pushover failed because');

$guzzleRequest = Mockery::mock(\Psr\Http\Message\RequestInterface::class);
$guzzleResponse = Mockery::mock(\Psr\Http\Message\ResponseInterface::class);
$guzzleResponse->shouldReceive('getStatusCode')->andReturn(400);
$guzzleResponse->shouldReceive('getBody')->andReturn('{"message": "[error_message]"}');

$this->guzzleClient->shouldReceive('post')->andThrow(new RequestException(null, $guzzleRequest, null));

Expand Down

0 comments on commit 2d57869

Please sign in to comment.