I'm not sure if this is exact, but you could give this post a read: http://fideloper.com/laravel4-error-handling
It gives an example of how to set up your own error handling class and you can call it from anywhere.
Let me know if it helps, if not, we may be able to take that concept and alter it for your needs.
Thanks for the help, but it's not that I want.
Currently I already did the next, using the ServiceProvider:
class ServiceProvider extends \Illuminate\Support\ServiceProvider {
public function register() {
$app = $this->app;
$app->error(function(Exception $exception, $code) {
// if the request is api specific
if (Request::is(Config::get('api.prefix') . '/*')) {
$message = $exception->getMessage()? : "Exeption";
return \Api\Response::exception($message);
}
});
$app->error(function(\Api\Exception\UnauthorizedException $exception, $code) {
return \Api\Response::unauthorized();
});
$app->error(function(\Api\Exception\AccessDeniedException $exception, $code) {
return \Api\Response::accessDenied();
});
$app->error(function(\Api\Exception\ValidationException $exception, $code) {
return \Api\Response::validationErrors(null, $exception->getErrors());
});
}
}
And it works great. The only thing which worries my is the Exception handling. As you see inside the handler I'm checking if the exception was thrown from the certain area.
While what I really want to do, is to be able to catch the exceptions only from the certain controller. And, in theory, I don't want to use the ServiceProvider, I want to catch them in the parent controller already.
Regards,
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community