node-connect.json 3.8 KB

123456
  1. {
  2. "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=\"connect\">\n<h2>Connect</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\">connect</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">require(</span><span style=\"color: #e8535a\">&#39;connect&#39;</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\">&#39;raven&#39;</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\">&#39;___DSN___&#39;</span><span style=\"color: #111111\">).install();</span>\n\n<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\">&#39;Broke!&#39;</span><span style=\"color: #111111\">);</span>\n<span style=\"color: #111111\">}</span>\n\n<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\">&#39;\\n&#39;</span><span style=\"color: #111111\">);</span>\n<span style=\"color: #111111\">}</span>\n\n<span style=\"color: #111111\">connect(</span>\n <span style=\"color: #34c08b; font-style: italic\">// The request handler be the first item</span>\n <span style=\"color: #111111\">Raven.requestHandler(),</span>\n\n <span style=\"color: #111111\">connect.bodyParser(),</span>\n <span style=\"color: #111111\">connect.cookieParser(),</span>\n <span style=\"color: #111111\">mainHandler,</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\">Raven.errorHandler(),</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Optional fallthrough error handler</span>\n <span style=\"color: #111111\">onError,</span>\n<span style=\"color: #111111\">).listen(</span><span style=\"color: #45c2c9\">3000</span><span style=\"color: #111111\">);</span>\n</pre></div>\n</div>\n</div>\n",
  3. "link": "https://docs.getsentry.com/clients/node/integrations/connect/",
  4. "id": "node-connect",
  5. "name": "Connect"
  6. }