How to use the captureException function from raven

Find comprehensive JavaScript raven.captureException code examples handpicked from public code repositorys.

raven.captureException is a method that captures an exception and sends it to the configured Sentry instance for logging and error monitoring.

15
16
17
18
19
20
21
22
23
24
Raven.context(function () {
    if(context_opts) {
        Raven.setContext(context_opts);
    };

    Raven.captureException(e, (sendErr, event) => {
        if(sendErr) {
            console.log('error on log to sentry')
        } else {
            console.log('raven logged event', event);
fork icon38
star icon63
watch icon0

252
253
254
255
256
257
258
259
260
261
                res.status(500);
                res.json({ success: false, error: "Internal server error." });
            }
            this.logError(req, res, e);
            if (useRaven()) {
                Raven.captureException(e, { tags: ravenTags });
            }
        }
    }
}));
fork icon96
star icon47
watch icon68

+ 16 other calls in file

How does raven.captureException work?

raven.captureException is a method provided by the Sentry error tracking system's Raven.js client library which allows developers to report errors and exceptions that occur in their application to the Sentry server for further investigation, by capturing and sending the relevant error information including the error message, stack trace, and additional metadata.

122
123
124
125
126
127
128
129
130
131
        _.each(game.getPlayers(), player => {
            debugData[player.name] = player.getState(player);
        });
    }

    Raven.captureException(e, { extra: debugData });
}

if(game) {
    game.addMessage('A Server error has occured processing your game state, apologies.  Your game may now be in an inconsistent state, or you may be able to continue.  The error has been logged.');
fork icon13
star icon16
watch icon6

78
79
80
81
82
83
84
85
86
87
     * If client's application does not catch this exception and node
     * crashes - we'll not get the report.
     * If client's application does catch an error an process it somehow
     * (e.g. mocha), we'll receive an exception in Sentry
     */
    Raven.captureException(e);

    throw e;
  }
};
fork icon5
star icon9
watch icon5

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
const Raven = require("raven");

// Initialize Raven with your DSN
Raven.config("YOUR_DSN").install();

try {
  // Some code that may throw an error
  throw new Error("Something went wrong!");
} catch (error) {
  // Capture the error with Raven
  Raven.captureException(error);
}

In this example, we first initialize Raven with our DSN using Raven.config('YOUR_DSN').install(). Then, we have some code that may throw an error in the try block. If an error is thrown, we catch it and use Raven.captureException to send the error to our Raven instance for logging and monitoring.

160
161
162
163
164
165
166
167
168
169

this._capturedExceptions.push(err);

// eslint-disable-next-line consistent-return
return new Promise((resolve, reject) => {
  Raven.captureException(
    err,
    (captureErr, result) => {
      if (captureErr) return reject(captureErr);
      return resolve(result);
fork icon5
star icon4
watch icon8

+ 2 other calls in file

57
58
59
60
61
62
63
64
65
66
if (error.name === 'GraphQLError') {
  extras.path = error.path;
}

if (isProfileErrorHandlerEnabled) {
  Raven.captureException(error);
}

logger.error('GraphQL Error: ', error.message);
return error;
fork icon3
star icon4
watch icon2

11
12
13
14
15
16
17
18
19
20
}

exports.log = (msg, meta) => {
  if (sentryEnabled) {
    if (meta.level === 'error' || meta.level === 'fatal') {
      Raven.captureException(msg, meta);
    }
    Raven.captureMessage(msg, meta);
  }
};
fork icon20
star icon0
watch icon2

9
10
11
12
13
14
15
16
  app.on('error', err => {
    if (ignoreErros.indexOf(err.output.statusCode) >= 0) { return }

    console.error(err)
    const requestData = Raven.getContext()
    if (Object.keys(requestData).length > 0) { Raven.captureException(err, { extra: requestData }) } else { Raven.captureException(err) }
  })
}
fork icon3
star icon1
watch icon0

+ 3 other calls in file

64
65
66
67
68
69
70
71
72
73
 * @param {String} code Error code
 * @param {Object} data Additional data to be sent to Sentry
 */
exports.error = (e, code, data) => {
  if (SENTRY_DSN) {
    Raven.captureException(e, { tags: { code }, extra: data });
  } else {
    console.error(e);
    console.error(code);
    console.error(data);
fork icon958
star icon0
watch icon4

43
44
45
46
47
48
49
50
51
52

  prefix += `${parameters.username}/${parameters.repository}`
}

if (config.get('sentryDSN')) {
  raven.captureException(err, {
    extra: parameters
  })
} else {
  console.log(`${prefix}`, err)
fork icon496
star icon2
watch icon2

27
28
29
30
31
32
33
34
35
36
   closing = true
}

process.on('uncaughtException', (err) => {
   console.error(`🔥  Uncaught exception!`, err)
   Raven.captureException(err, sendErr => { // This callback fires once the report has been sent to Sentry
      if (sendErr)
         console.error('🔥  Failed to send captured exception to Sentry!')
      else
         console.log('⚡  Captured exception and sent it to Sentry successfully')
fork icon0
star icon1
watch icon2

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13

module.exports = function errorHandler(err, req, res, next) {
  winston.log('error', err);

  if (config.app.sentry.secret) {
    Raven.captureException(err);
  }

  if (req.accepts('html')) {
    return next(err);
fork icon0
star icon1
watch icon1

32
33
34
35
36
37
38
39
        })
      }
    }
    const room = process.env.SENTRY_CHANNEL || '#desarrollo'
    robot.send({room: room}, `An error has occurred: \`${err.message}\``)
    Raven.captureException(err)
  })
}
fork icon1
star icon0
watch icon0

3
4
5
6
7
8
9
10
11
12
13
var path = require('path');
var RELEASE_ID = fs.readFileSync(
  path.join(__dirname, '../../release_id.txt'), 'utf8').trim(); // Need to trim newline char from end


var Raven = require('raven');
var originalCaptureException = Raven.captureException;
Raven.config(
  process.env.NODE_ENV === 'production' ? process.env.SENTRY_DSN : undefined, // Only set DSN
  // in production, so that only in production do we actually send errors to Sentry.
  {
fork icon0
star icon0
watch icon1

38
39
40
41
42
43
44
45
46
47
48
}) {
  const extraWithMsg = Object.assign({
    msg
  }, extra)


  Raven.captureException(error, {
    request,
    user,
    tags,
    extra: extraWithMsg,
fork icon0
star icon0
watch icon0

34
35
36
37
38
39
40
41
42
43
reportError(err, extra) {
  if (this.inSpecMode || this.inDevMode) {
    return;
  }

  Raven.captureException(err, {
    extra: extra,
    tags: {
      platform: process.platform,
      version: this.getVersion(),
fork icon0
star icon0
watch icon0

41
42
43
44
45
46
47
48


  return Raven;
});


exports.Raven = Raven;
exports.captureException = (...args) => Raven.captureException(...args);
fork icon0
star icon0
watch icon0

10
11
12
13
14
15
16
17
18
19
```javascript
try {
  throw new Error();
} catch (e) {
  // You can get eventId either as the synchronous return value, or via the callback
  var eventId = Raven.captureException(e, function (sendErr, eventId) {
    // This callback fires once the report has been sent to Sentry
    if (sendErr) {
      console.error('Failed to send captured exception to Sentry');
    } else {
fork icon0
star icon0
watch icon0

+ 5 other calls in file

21
22
23
24
25
26
27
28
29
30
// use app.toAsyncFunction to support both generator function and async function
try {
  await ctx.app.toAsyncFunction(scope)(ctx)
  ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start)
} catch (err) {
  Raven.captureException(err, (ravenError, eventId) => {
    if (ravenError) {
      ctx.coreLogger.error(ravenError)
    }
  })
fork icon0
star icon0
watch icon9