Skip to content

Commit

Permalink
Use json response message only it's tagged with application/json
Browse files Browse the repository at this point in the history
content-type.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed May 26, 2019
1 parent 68189de commit 387590f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public function validate()
{
$payload = $this->toArray();
$statusCode = $this->getStatusCode();
$contentType = $this->getHeader('Content-Type')[0] ?? null;

if ($statusCode === 401) {
throw new Exceptions\NotAuthorizedException($this, $this->getReasonPhrase());
} elseif ($statusCode === 500) {
} elseif ($statusCode === 500 && $contentType === 'application/json') {
throw new HttpException($this, $this->toArray()['message']);
} elseif ($statusCode !== 200) {
throw new HttpException($this, $this->getReasonPhrase());
Expand Down

0 comments on commit 387590f

Please sign in to comment.