Support the ongoing development of Laravel.io →
Architecture
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

@ayyobro

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,

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.