Skip to content

Commit

Permalink
Merge pull request #16 from lucassabreu/master
Browse files Browse the repository at this point in the history
(fix): exception will never be a int
  • Loading branch information
veewee authored Jul 8, 2021
2 parents af35ef0 + 8c45d35 commit 46fdf98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/Http/ExceptionApiProblemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,17 @@ public function it_should_deal_with_string_exception_codes(): void
'detail' => $message,
]);
}

public function it_should_use_code_as_status_code_when_valid_http_status_code_error(): void
{
$message = 'an honest error';
$this->beConstructedWith(new \InvalidArgumentException($message, 400));

$this->toArray()->shouldBe([
'status' => 400,
'type' => HttpApiProblem::TYPE_HTTP_RFC,
'title' => HttpApiProblem::getTitleForStatusCode(400),
'detail' => $message,
]);
}
}
2 changes: 1 addition & 1 deletion src/Http/ExceptionApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(Throwable $exception)
{
$this->exception = $exception;
$exceptionCode = $exception->getCode();
$statusCode = is_int($exception) && $exceptionCode >= 400 && $exceptionCode <= 599
$statusCode = is_int($exceptionCode) && $exceptionCode >= 400 && $exceptionCode <= 599
? $exceptionCode
: 500;

Expand Down

0 comments on commit 46fdf98

Please sign in to comment.