Skip to content

Commit bb31bd2

Browse files
committed
Merge branch 'release/0.9.12'
2 parents 49425b8 + 5b9e95c commit bb31bd2

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
lines changed

.version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"strategy": "semver",
33
"major": 0,
44
"minor": 9,
5-
"patch": 11,
5+
"patch": 12,
66
"build": 0
77
}

src/Mvc/Application.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Neuron\Log\Log;
1313
use Neuron\Mvc\Controllers\Factory;
1414
use Neuron\Mvc\Events\Http404;
15+
use Neuron\Mvc\Events\Http500;
1516
use Neuron\Mvc\Requests\Request;
1617
use Neuron\Patterns\Registry;
1718
use Neuron\Routing\RequestMethod;
@@ -235,7 +236,7 @@ protected function onRun() : void
235236
$route = $params['REQUEST_URI'] ?? '/';
236237
$ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
237238

238-
\Neuron\Application\CrossCutting\Event::emit( new Events\RequestReceivedEvent(
239+
Event::emit( new Events\RequestReceivedEvent(
239240
$method,
240241
$route,
241242
$ip,
@@ -318,6 +319,38 @@ public function executeController( array $parameters, string $requestName = '' )
318319
)
319320
);
320321
}
322+
catch( \Throwable $e )
323+
{
324+
Log::error( "Exception in controller: " . $e->getMessage() );
325+
326+
Event::emit( new Http500(
327+
$parameters['route'] ?? 'unknown',
328+
get_class( $e ),
329+
$e->getMessage(),
330+
$e->getFile(),
331+
$e->getLine()
332+
) );
333+
334+
$this->onCrash(
335+
[
336+
'type' => get_class( $e ),
337+
'message' => $e->getMessage(),
338+
'file' => $e->getFile(),
339+
'line' => $e->getLine()
340+
]
341+
);
342+
343+
return $this->executeController(
344+
array_merge(
345+
$parameters,
346+
[
347+
"Controller" => "Neuron\Mvc\Controllers\HttpCodes@code500",
348+
"error" => $e->getMessage(),
349+
"type" => get_class( $e )
350+
]
351+
)
352+
);
353+
}
321354
}
322355

323356
/**

src/Mvc/Controllers/HttpCodes.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,18 @@ public function code404( Request $request ) : string
2020
'404'
2121
);
2222
}
23+
24+
public function code500( Request $request ) : string
25+
{
26+
return $this->renderHtml(
27+
HttpResponseStatus::INTERNAL_SERVER_ERROR,
28+
array_merge(
29+
$request->getRouteParameters(),
30+
[
31+
"title" => "Internal Server Error",
32+
]
33+
),
34+
'500'
35+
);
36+
}
2337
}

src/Mvc/Events/Http500.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Neuron\Mvc\Events;
4+
5+
use Neuron\Events\IEvent;
6+
7+
/**
8+
* Event generated when a 500 error takes place.
9+
* Happens before the rendering of the error page.
10+
*/
11+
class Http500 implements IEvent
12+
{
13+
public string $route;
14+
public string $exceptionType;
15+
public string $message;
16+
public string $file;
17+
public int $line;
18+
19+
public function __construct( string $route, string $exceptionType, string $message, string $file, int $line )
20+
{
21+
$this->route = $route;
22+
$this->exceptionType = $exceptionType;
23+
$this->message = $message;
24+
$this->file = $file;
25+
$this->line = $line;
26+
}
27+
}

versionlog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
## 0.9.12 2025-11-27
2+
13
## 0.9.11 2025-11-27
4+
* Added 500 error page.
25

36
## 0.9.10 2025-11-27
47
* Updated markdown to respect file paths.

0 commit comments

Comments
 (0)