route
route copied to clipboard
How can I assign controller to errors http ?
I like send a Response if Method Not Found o route Not Found
example:
<?php
$router
->group("/dashboard", function () { /* code */ })
->set500([ErrorController::class, "handle500"])
->setStrategy(new ApplicationStrategy());
class ErrorController
{
public function handle500($request)
{
return Response::html("<h1>Sorry, exists problem!</<h1>");
}
// handle401, handle401, handle402, handle403, handle404, handle419, handle429, handle503
}
$router
->group("/api/v1", function () { /* code */ })
->set500([ErrorJsonController::class, "handle500"])
->setStrategy(new JsonStrategy());
class ErrorJsonController
{
public function handle500($request)
{
return Response::json(["message" => "Sorry, exists problem!"]);
}
// handle401, handle401, handle402, handle403, handle404, handle419, handle429, handle503
}
or
<?php
$router
->group("/dashboard", function () { /* code */ })
->setErrorHandle(ErrorController::class)
->setStrategy(new ApplicationStrategy());
class ErrorController
{
// use dynamic
public function handle500($request)
{
return Response::html("<h1>Sorry, exists problem!</<h1>");
}
// handle401, handle401, handle402, handle403, handle404, handle419, handle429, handle503
}
$router
->group("/api/v1", function () { /* code */ })
->setErrorHandle(ErrorJsonController::class)
->setStrategy(new JsonStrategy());
class ErrorJsonController
{
// use dynamic
public function handle500($request)
{
return Response::json(["message" => "Sorry, exists problem!"]);
}
// handle401, handle401, handle402, handle403, handle404, handle419, handle429, handle503
}