Skip to content

Commit

Permalink
Rolled back * **\SlimMvcTools\MvcRouteHandler** now throws **\Slim\Ex…
Browse files Browse the repository at this point in the history
…ception\HttpInternalServerErrorException** when the execution of specified action method in the uri received from a client throws an exception that is not handled in the specified action method
  • Loading branch information
rotimi committed Feb 24, 2025
1 parent 6f02e29 commit 723af53
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
20 changes: 0 additions & 20 deletions src/MvcRouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,6 @@ public function __invoke(
$log_message,
$e
);

} catch (\Throwable $e) {

if(! $e instanceof \Slim\Exception\HttpSpecializedException) {

//500 Internal server error: An Exception or Error was thrown when trying to execute action method on the controller.
/** @psalm-suppress InvalidOperand */
$log_message =
"`".__FILE__."` on line ".__LINE__
. sprintf(': Error occured when calling `%s`(...) on an instance of `%s` for the uri `%s`.' . PHP_EOL . 'Error: `%s`', $action_method, $controller_obj::class, $req->getUri()->__toString(), $e->getMessage());

/** @psalm-suppress PossiblyNullArgument */
throw Utils::createSlimHttpExceptionWithLocalizedDescription(
$this->app->getContainer(),
SlimHttpExceptionClassNames::HttpInternalServerErrorException,
$req,
$log_message,
$e
);
}
}

return $controller_obj->postAction($resp);
Expand Down
30 changes: 0 additions & 30 deletions tests/MvcRouteHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,36 +174,6 @@ public function testThat___invoke_WorksAsExpected3() {
$mvc_route_handler1($this->newRequest(), $this->newResponse(), $args);
}

/**
* @runInSeparateProcess
*/
public function testThat___invoke_WorksAsExpected4() {

// When a conntroller method that throws an exception is called
$this->expectException(\Slim\Exception\HttpInternalServerErrorException::class);
$message = '/.*: Error occured when calling `actionThrowException`.*/';
$this->expectExceptionMessageMatches($message);

$container = $this->getContainer();
\Slim\Factory\AppFactory::setContainer($container);
$app = \Slim\Factory\AppFactory::create();


$auto_prepend_action_to_method_name = true;

$mvc_route_handler1 = new \SlimMvcTools\MvcRouteHandler(
$app, \SlimMvcTools\Controllers\BaseController::class,
'actionIndex', $auto_prepend_action_to_method_name
);

$args = [
'parameters' => '',
'action' => 'action-throw-exception', // method that throws exception
'controller' => 'stand-alone-controller'
];
$mvc_route_handler1($this->newRequest(), $this->newResponse(), $args);
}

public function testThat_validateMethodName_WorksAsExpected() {

$this->expectException(\Slim\Exception\HttpBadRequestException::class);
Expand Down

0 comments on commit 723af53

Please sign in to comment.