Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use heimdal ExceptionHandler just in API #16

Open
VictorAssis opened this issue Sep 14, 2017 · 3 comments
Open

Use heimdal ExceptionHandler just in API #16

VictorAssis opened this issue Sep 14, 2017 · 3 comments

Comments

@VictorAssis
Copy link

Hello, I am creating the API of a system that already has an administrator module running today. Is it possible for Laravel to use the Heindal Handler only in the API module?

@VictorAssis
Copy link
Author

I've found a solution, but I do not know if it's for the best.

  1. Remove singleton from bootstrap/app.php;
  2. Change the app/Exceptions/Handler.php render method to:
public function render($request, Exception $exception)
{
    if($request->is('api/*')) {
        $handler = new \Optimus\Heimdal\ExceptionHandler($this->container);
        return $handler->render($request, $exception);
    }
    return parent::render($request, $exception);
}

@VictorAssis VictorAssis changed the title Usei heimdal ExceptionHandler just in API Use heimdal ExceptionHandler just in API Sep 21, 2017
@keremcankaya0
Copy link

keremcankaya0 commented Jan 10, 2018

Thanks for the solution @VictorAssis
`
$handler = new APIExceptionHandler($this->container);

    if ($request->is('api/*')) {
        return $handler->render($request, $exception);
    }
    $handler->report($exception);
    return parent::render($request, $exception);`

If anyone needs to use reporter from the library for web

@2jan
Copy link

2jan commented Mar 8, 2018

You can also detect request type (API/web) during binding procedure and provide appropriate ExceptionHandler class.
In your bootstrap/app.php add something similar to:

$app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, function($app) {  
  if(request()->is('api/*')) {
    return new Optimus\Heimdal\ExceptionHandler($app);
  }
  return new App\Exceptions\Handler($app);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants