123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>Raven is distributed via <code class=\"docutils literal\"><span class=\"pre\">npm</span></code>:</p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>$ npm install raven --save\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"configuring-the-client\">\n<h2>Configuring the Client</h2>\n<p>Next you need to initialize the Raven client and configure it to use your <a class=\"reference external\" href=\"https://docs.sentry.io/clients/node/config/\">Sentry DSN</a>:</p>\n<div class=\"highlight-javascript\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">var</span> <span style=\"color: #111111\">Raven</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">require(</span><span style=\"color: #e8535a\">'raven'</span><span style=\"color: #111111\">);</span>\n<span style=\"color: #111111\">Raven.config(</span><span style=\"color: #e8535a\">'___DSN___'</span><span style=\"color: #111111\">).install();</span>\n</pre></div>\n</div>\n<p>At this point, Raven is set up to capture and report any uncaught exceptions.</p>\n<p>You can optionally pass an object of configuration options as the 2nd argument to <cite>Raven.config</cite>. For\nmore information, see <a class=\"reference internal\" href=\"https://docs.getsentry.com/clients/node/config/\"><em>Configuration</em></a>.</p>\n</div>\n\n\n<div class=\"section\" id=\"reporting-errors\">\n<h2>Reporting Errors</h2>\n<p>Raven’s <code class=\"docutils literal\"><span class=\"pre\">install</span></code> method sets up a global handler to automatically capture any uncaught exceptions. You can also report errors manually with <code class=\"docutils literal\"><span class=\"pre\">try...catch</span></code> and\na call to <code class=\"docutils literal\"><span class=\"pre\">captureException</span></code>:</p>\n<div class=\"highlight-javascript\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">try</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">doSomething(a[</span><span style=\"color: #45c2c9\">0</span><span style=\"color: #111111\">]);</span>\n<span style=\"color: #111111\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #111111\">(e)</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">Raven.captureException(e);</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>You can also use <code class=\"docutils literal\"><span class=\"pre\">wrap</span></code> and <code class=\"docutils literal\"><span class=\"pre\">context</span></code> to have Raven wrap a function and automatically capture any exceptions it throws:</p>\n<div class=\"highlight-javascript\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">Raven.context(</span><span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">()</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">doSomething(a[</span><span style=\"color: #45c2c9\">0</span><span style=\"color: #111111\">]);</span>\n<span style=\"color: #111111\">});</span>\n</pre></div>\n</div>\n<p>For more information on reporting errors, see <a class=\"reference internal\" href=\"https://docs.getsentry.com/clients/node/usage/\"><em>Usage</em></a>.</p>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/node/",
- "id": "node",
- "name": "Node.js"
- }
|