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

ignoreErrors not working #6100

Closed
vcarel opened this issue Sep 12, 2017 · 7 comments
Closed

ignoreErrors not working #6100

vcarel opened this issue Sep 12, 2017 · 7 comments

Comments

@vcarel
Copy link

vcarel commented Sep 12, 2017

I'm trying to make ignoreErrors work, and I can't figure how.
I'm using express with the following setup:

import express from 'express'
import Raven from 'raven'

Raven.config('the dsn', { ignoreErrors: ['BOOM'] }).install()

const app = express()

app.use(Raven.requestHandler())

app.get('/boom', (req, res) => {
  throw new Error('BOOM')
})

app.use(Raven.errorHandler())

When I make a request to http://myserver/boom, Sentry captures the error.

I tried /BOOM/ and /.*BOOM.*/ for ignoreErrors. The error is always sent.
I'm on raven@2.1.2

@mattrobenolt
Copy link
Contributor

@kamilogorek does raven-node even support this?

I’m going to close the ticket here at any rate since it’s on the wrong repository. See https://github.com/getsentry/raven-node

@kamilogorek
Copy link
Contributor

@mattrobenolt it doesn't, ignoreErrors is available in raven-js, not raven-node. @vcarel please use shouldSendCallback method to filter unwanted errors.

@vcarel
Copy link
Author

vcarel commented Sep 13, 2017

@mattrobenolt @kamilogorek My apologizes, I confused raven-js and raven-node.
BTW, shouldn't the APIs be consistant on this point ?

@kamilogorek
Copy link
Contributor

kamilogorek commented Sep 13, 2017

@vcarel they will be 1:1 compatible, we're working on it :)

@mhd999
Copy link

mhd999 commented Jan 18, 2018

@kamilogorek Any update on this feature ?

@kamilogorek
Copy link
Contributor

@mhd999 we're in the process of creating next major version of JS SDK – getsentry/sentry-javascript#1149
We'll definitely try to keep everyone updated as we go :)

@adamreisnz
Copy link

I've written a custom helper for this based on code found in raven-js, you can use it to support ignoreErrors while waiting for the SDK's to be unified.

Helper:

/**
 * Join an array of string/regex patterns into a single regex (adapted from raven-js)
 */
function joinRegex(patterns) {

  //Initialize sources
  const sources = [];

  //Loop patterns
  for (const pattern of patterns) {

    //If it's a string, we need to escape it
    if (typeof pattern === 'string') {
      sources.push(pattern.replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'));
    }

    //If it's a regular expression already, we want to extract the source
    else if (pattern && pattern.source) {
      sources.push(pattern.source);
    }

    //Intentionally skip other cases
  }

  //Return combined regular expression
  return new RegExp(sources.join('|'), 'i');
}

Configuration converter:

if (Array.isArray(cfg.ignoreErrors) && cfg.ignoreErrors.length > 0) {
  const ignoreErrors = joinRegex(cfg.ignoreErrors);
  cfg.shouldSendCallback = function(data) {
    if (data.message && typeof data.message.match === 'function') {
      return !data.message.match(ignoreErrors);
    }
    return true;
  };
}

This essentially defines a shouldSendCallback config property if you've passed ignoreErrors instead.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants