Using Raygun for error handling of Node.js applications _node.js

Source: Internet
Author: User
Tags error handling

With our Raygun4node package, you can provide a convenient way to send your node.js error to Raygun. It can be figure by using NPM installation:

NPM Install Raygun

It provides you with a Raygun client that you can use to configure your API key and can be used to manually send error messages. But later on you might say, "I don't want to send all the bugs to Raygun by hand, which sounds like a lot of work to do!" If you're using a express.js, the Express processor can easily solve the concern.

var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
App.use (Raygunclient.expresshandler);

In other cases you may just want to listen for an exception uncaughtexception that has not been caught and send an error message in this way.

var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
Process.on (' Uncaughtexception ', function (err) {
 raygunclient.send (err);
});
 

If you're going to start doing this, you have to understand what it means. But when a time bubble goes back to the event loop, the event will be sent out. If you add a listener to this event, the default action will not happen again. The default action prints out the call stack information and exits the process. If you continue after this trigger, your node process will be in a state that is not defined. The Node.js document specifically mentions that you should not use this thing, and that it may be removed in the future. The recommended alternative is to use domain domains. Here's a small, simple example where you can see how Raygun clients fit in with your domain.


var domain = require (' domain ');
var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
var server = require (' http '). Createserver (function (req, res) {
 var d = domain.create ();
 D.on (' Error ', function (err) {
  raygunclient.send (err);
  Clean up and End
 });
 D.add (req);
 D.add (res);
 D.run (function () {
  //Handle the Req, res
 });
Server.listen (3000);

Hopefully this will help you better understand the error handling in the Node.js using Raygun.

Continuous cleanup Error!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.