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=\"express\">\n<h2>Express</h2>\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\">app</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">require(</span><span style=\"color: #e8535a\">'express'</span><span style=\"color: #111111\">)();</span>\n<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\n<span style=\"color: #34c08b; font-style: italic\">// Must configure Raven before doing anything else with it</span>\n<span style=\"color: #111111\">Raven.config(</span><span style=\"color: #e8535a\">'__DSN__'</span><span style=\"color: #111111\">).install();</span>\n\n<span style=\"color: #34c08b; font-style: italic\">// The request handler must be the first middleware on the app</span>\n<span style=\"color: #111111\">app.use(Raven.requestHandler());</span>\n\n<span style=\"color: #111111\">app.get(</span><span style=\"color: #e8535a\">'/'</span><span style=\"color: #111111\">,</span> <span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">mainHandler(req,</span> <span style=\"color: #111111\">res)</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #2eb0f7\">throw</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #2eb0f7\">Error</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">'Broke!'</span><span style=\"color: #111111\">);</span>\n<span style=\"color: #111111\">});</span>\n\n<span style=\"color: #34c08b; font-style: italic\">// The error handler must be before any other error middleware</span>\n<span style=\"color: #111111\">app.use(Raven.errorHandler());</span>\n\n<span style=\"color: #34c08b; font-style: italic\">// Optional fallthrough error handler</span>\n<span style=\"color: #111111\">app.use(</span><span style=\"color: #2eb0f7\">function</span> <span style=\"color: #111111\">onError(err,</span> <span style=\"color: #111111\">req,</span> <span style=\"color: #111111\">res,</span> <span style=\"color: #111111\">next)</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// The error id is attached to `res.sentry` to be returned</span>\n <span style=\"color: #34c08b; font-style: italic\">// and optionally displayed to the user for support.</span>\n <span style=\"color: #111111\">res.statusCode</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #45c2c9\">500</span><span style=\"color: #111111\">;</span>\n <span style=\"color: #111111\">res.end(res.sentry</span> <span style=\"color: #4b4f5c\">+</span> <span style=\"color: #e8535a\">'\\n'</span><span style=\"color: #111111\">);</span>\n<span style=\"color: #111111\">});</span>\n\n<span style=\"color: #111111\">app.listen(</span><span style=\"color: #45c2c9\">3000</span><span style=\"color: #111111\">);</span>\n</pre></div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/node/integrations/express/",
- "id": "node-express",
- "name": "Express"
- }
|