Skip to content

Commit 46fdf98

Browse files
authored
Merge pull request #16 from lucassabreu/master
(fix): exception will never be a int
2 parents af35ef0 + 8c45d35 commit 46fdf98

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

spec/Http/ExceptionApiProblemSpec.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,17 @@ public function it_should_deal_with_string_exception_codes(): void
144144
'detail' => $message,
145145
]);
146146
}
147+
148+
public function it_should_use_code_as_status_code_when_valid_http_status_code_error(): void
149+
{
150+
$message = 'an honest error';
151+
$this->beConstructedWith(new \InvalidArgumentException($message, 400));
152+
153+
$this->toArray()->shouldBe([
154+
'status' => 400,
155+
'type' => HttpApiProblem::TYPE_HTTP_RFC,
156+
'title' => HttpApiProblem::getTitleForStatusCode(400),
157+
'detail' => $message,
158+
]);
159+
}
147160
}

src/Http/ExceptionApiProblem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct(Throwable $exception)
1818
{
1919
$this->exception = $exception;
2020
$exceptionCode = $exception->getCode();
21-
$statusCode = is_int($exception) && $exceptionCode >= 400 && $exceptionCode <= 599
21+
$statusCode = is_int($exceptionCode) && $exceptionCode >= 400 && $exceptionCode <= 599
2222
? $exceptionCode
2323
: 500;
2424

0 commit comments

Comments
 (0)