Skip to content

Commit e0046b2

Browse files
authored
fix(router): preserve http status during development exceptions (#2133)
1 parent cf6a6a8 commit e0046b2

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/router/src/Exceptions/DevelopmentException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Tempest\Http\IsResponse;
1111
use Tempest\Http\Request;
1212
use Tempest\Http\Response;
13-
use Tempest\Http\Status;
1413
use Tempest\Support\Filesystem;
1514
use Tempest\View\Exceptions\ViewCompilationFailed;
1615
use Tempest\View\GenericView;
@@ -27,7 +26,7 @@ final class DevelopmentException implements Response
2726

2827
public function __construct(Throwable $throwable, Response $response, Request $request)
2928
{
30-
$this->status = Status::INTERNAL_SERVER_ERROR;
29+
$this->status = $response->status;
3130

3231
if (! Filesystem\exists(__DIR__ . '/local/dist/main.js')) {
3332
$this->body = 'The development exception interface is not built.';

tests/Integration/Http/Exceptions/HtmlExceptionRendererTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ public function renders_development_exception_in_local_environment(): void
120120
);
121121
}
122122

123+
#[Test]
124+
public function development_exception_preserves_http_request_failed_status(): void
125+
{
126+
$this->container->singleton(Environment::class, Environment::LOCAL);
127+
$this->container->singleton(GenericRequest::class, new GenericRequest(
128+
method: Method::GET,
129+
uri: '/',
130+
));
131+
132+
$response = $this->renderer->render(new HttpRequestFailed(Status::NOT_ACCEPTABLE));
133+
134+
$this->assertInstanceOf(DevelopmentException::class, $response);
135+
$this->assertSame(Status::NOT_ACCEPTABLE, $response->status);
136+
}
137+
123138
#[Test]
124139
public function does_not_render_development_exception_for_not_found_in_local(): void
125140
{

0 commit comments

Comments
 (0)