JulianMar / nuxt-bugsnag

Bugsnag module for nuxt.js
MIT License
49 stars 18 forks source link

uncaught errors on server #59

Closed natemate90 closed 1 year ago

natemate90 commented 1 year ago

Hi @JulianMar, one more question from my side. Do I understand it correctly that in the current state of nuxt, the nuxt-bugsnag module won't auto-report any uncaught server errors to bugsnag? I tried using the playground (nuxt-bugsnag version 7.0.0) but saw that the server error on the server page doesn't seem to report the error anymore.

Reproduce:

  1. clone module
  2. yarn install && yarn dev
  3. add correct module config
  4. visit http://localhost:3000/borked
natemate90 commented 1 year ago

I've found meanwhile a solution to hook into the h3 errors myself without breaking the error page. (Partially inspired by this thread). It seems that a similar solution was present in an earlier version:

import type { NitroApp, NitroAppPlugin } from "nitropack";

export default <NitroAppPlugin>function (nitroApp: NitroApp) {

  const h3OnError = nitroApp.h3App.options.onError;

  nitroApp.h3App.options.onError = function (error, event) {
    console.log(event.headers); // for additional data i.e. in the onErrorCallback as you like
    nitroApp.$bugsnag.notify(error);

    if (h3OnError !== undefined) {
      return h3OnError(error, event); // makes sure the error page doesn't break :-)
    }
    return;
  };
};

Tested on nuxt 3.7.1

JulianMar commented 1 year ago

Hey, you closed this again. Is there a reason why? Your approach looks good and I will test it again, but as far as I can tell it should be the same solution as previously and should still break the error page. I will test it anyway :)