rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar
https://docs.rollbar.com/docs/javascript
MIT License
567 stars 212 forks source link

Custom error hook not working in client-snippet #1143

Open mirankorkmaz opened 3 weeks ago

mirankorkmaz commented 3 weeks ago

I have a hook called logError in my React code that reports to rollbar with rollbar.error.

It looks like this:

export const logError = (labeledMessage: string, error: any = {}) => {
  console.error(
    JSON.stringify({
      message: labeledMessage,
      error: inspect(error),
    }),
  );
  rollbar.error(labeledMessage, error);
};

It is used like this in other components:

 if (!mapboxgl.accessToken) {
        logError('[Map]: Access token is missing');
        setHasError(true);
      }

In my rollbar conf

var _rollbarConfig = {
    accessToken: "TOKEN",
    captureUncaught: true,
    captureUnhandledRejections: true,
    payload: {
        environment: "development",
        client: {
          javascript: {
            source_map_enabled: true,
            guess_uncaught_frames: true
          }
        }
    },
    checkIgnore: function(isUncaught, args, payload) {
        var error = args[0];
        if (error && error.message) {
        return false; // Do not ignore, send to Rollbar
      }

      return true; // Ignore all other errors
    }
};

It seems to work ignoring all other errors client side in rollbar. For example, I triggered a hydration error that is not reported to rollbar with this checkIgnore function. It is reporting when removing the checkIgnore snippet.

However, the logError logError('[Map]: Access token is missing'); is not reporting at all, even when I'm triggering it. Can anyone spot the wrong in checkIgnore? How do I only report logError-hook to rollbar client side?

linear[bot] commented 3 weeks ago

SDK-364 Custom error hook not working in client-snippet