craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

Logging Element API errors #117

Closed oddnavy closed 3 years ago

oddnavy commented 4 years ago

Is there a way to log exceptions caught in the element-api actionIndex? The code looks like it catches exceptions thrown.

https://github.com/craftcms/element-api/blob/v2/src/controllers/DefaultController.php#L165

For context, we want to log exceptions that cause 500s in my element-api to Rollbar.

Current code to log exceptions:

Event::on(
  ErrorHandler::class,
  ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
  function (ExceptionEvent $event) {
    Rollbar::error($event->exception);
  }
);
yoannisj commented 3 years ago

@oddnavy if the controller logs thrown exceptions (I just opened a PR to add logging), I believe you should be able to send all errors by adding a log target for Rollbar in your project's config/app.php file.

brandonkelly commented 3 years ago

Just released Element API 2.7.0, which now logs all exceptions thrown while resolving requests.