Skip to content

Commit

Permalink
Merge pull request #15 from samrap/develop
Browse files Browse the repository at this point in the history
Improve error message for unknown reasons.
  • Loading branch information
Sam Rapaport committed Feb 23, 2018
2 parents d651c9a + 3ae407e commit de3bf5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Gemini.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ protected function createExceptionFromResponse(ResponseInterface $response) : Ge
return new $exception($payload['message']);
}

return new GeminiException(
'An unknown error occurred while talking to the API.'
);
return new GeminiException("[{$payload['reason']}] {$payload['message']}");
}
}
14 changes: 14 additions & 0 deletions tests/Unit/GeminiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ public function it_throws_the_respective_exception_from_an_error_response()
]);
}

/**
* @test
* @expectedException \Samrap\Gemini\Exceptions\GeminiException
* @expectedExceptionMessage [Bad Request] Supplied parameter is not a valid option
*/
public function unknown_exception_contains_reason_and_message()
{
$this->sendFailedRequest(400, [
'result' => 'error',
'reason' => 'Bad Request',
'message' => 'Supplied parameter is not a valid option',
]);
}

/**
* Send a request that should.
*
Expand Down

0 comments on commit de3bf5b

Please sign in to comment.