Example #1
0
    afterTileRender: function(req, res, tile, headers, callback) {
        try {
            // Complete render pipline first, add cache header for
            // 30 days
            headers['Cache-Control'] = 'max-age=2592000';
            callback(null, tile, headers);

            // Check if the environment is set up to cache tiles
            if (!shouldCacheRequest(req)) { return; }

            var cleanUrl = req.url[0] === '/' ? req.url.substr(1) : req.url,
                s3Obj = new aws.S3({params: {Bucket: tileCacheBucket, Key: cleanUrl}}),
                body;

            if (Buffer.isBuffer(tile)) {
                body = new stream.PassThrough();
                body.end(tile);
            } else {
                body = JSON.stringify(tile);
            }

            if (body) {
                s3Obj.upload({Body: body}, function(err, data) {
                    if (err) {
                        throw (err);
                    }
                });
            }

            callback(null);
        } catch (ex) {
            rollbar.handleError(ex, req);
            callback(ex, null);
        }
    },
Example #2
0
 beforeTileRender: function(req, res, callback) {
     try {
         callback(null);
     } catch (ex) {
         rollbar.handleError(ex, req);
         callback(ex);
     }
 },
Example #3
0
 knex.on('query', function(data) {
   if (_.contains(data.bindings, 'undefined')) {
     rollbar.handleError('undefined value in SQL query', {
       sql: data.sql,
       bindings: data.bindings
     });
   }
 });
    var respond = error => {
      if (error && error.stack) rollbar.handleError(error, req)

      return resolve(res.view('popupDone', {
        error,
        context: req.session.authContext || 'oauth',
        layout: null,
        returnDomain: req.session.returnDomain
      }))
    }
Example #5
0
 }).catch(function(error) {
   console.log('error');
   console.log(error);
   if (config.rollbar) {
     rollbar.handleError(error);
   }
   if (config.opbeat) {
     opbeat.captureError(error);
   }
 });
Example #6
0
    req2params: function(req, callback) {
        try {
            var tableId = req.params.tableId,
                tableName = tables[tableId];

            req.params.table = tableName;
            req.params.dbname = dbName;
            req.params.style = styles;
            req.params.interactivity = interactivity[tableName];
            callback(null, req);
        } catch (ex) {
            rollbar.handleError(ex, req);
            callback(ex, null);
        }
    }
Example #7
0
app.post('/github/delivery', function(req, res) {
  debug('delivery');

  var signature = req.headers['x-hub-signature'];
  var event = req.headers['x-github-event'];
  var id = req.headers['x-github-delivery'];

  var payload = '';
  try {
    payload = JSON.stringify(req.body);
  } catch (error) {
    rollbar.handleError(error);
  }

  var hmac = crypto.createHmac('sha1', config.github.secret);
  hmac.update(payload);
  var calculatedSignature = 'sha1=' + hmac.digest('hex');

  if (!signature) {
    debug('No X-Hub-Signature found on request');
    res.status(400).send('No X-Hub-Signature found on request');
  } else if (!event) {
    debug('No X-Github-Event found on request');
    res.status(400).send('No X-Github-Event found on request');
  } else if (!id) {
    debug('No X-Github-Delivery found on request');
    res.status(400).send('No X-Github-Delivery found on request');
  } else if (signature !== calculatedSignature) {
    debug('X-Hub-Signature does not match blob signature');
    res.status(400).send('X-Hub-Signature does not match blob signature');
  } else {
    debug('processing payload');

    issueHandler({
      event: event,
      id: id,
      payload: req.body,
      protocol: req.protocol,
      host: req.headers.host,
      url: req.url
    });

    res.send({
      'ok': true
    });
  }
});
Example #8
0
 vhostChecker.on('error', function (err, source) {
   if (err.known) {
     console.error(err.message);
   }
   else {
     console.error(err);
     console.error(err.stack);
   }
   if (err.body) {
     console.error('<Error Response Body>');
     console.error(err.body);
     console.error('</Error Response Body>');
   }
   if (this.options.rollbar) {
     rollbar.handleError(err);
   }
 });
Example #9
0
export default () => function*(next) {
    try {
        yield* next
    } catch (e) {
        rollbar.handleError(e, this.request)
        if (e && e.status) {
            // could use template methods to render error page
            this.body = e.message
            this.statusCode = e.status
        } else {
            this.body = 'Error 500'
            this.statusCode = 500
            if (e) console.error(e.message, e.stack)
            else console.error('Error!')
        }
    }
}
Example #10
0
Rollbar.prototype.log = function(level, msg, meta, callback) {
  var self = this;

  if (this.silent) {
    return callback(null, true);
  }

  var logged = function(err) {
    if (err) {
      return callback(err);
    }

    self.emit('logged');
    callback(null, true);
  };

  if (/emerg/i.test(level)) {
    level = 'crit';
  } else if (/warn/i.test(level)) {
    level = 'warning';
  }

  if (/error/i.test(level) && (msg instanceof Error || meta instanceof Error)) {
    if (msg instanceof Error) {
      meta = {
        level : level,
        custom : typeof meta === 'object' ? meta : {
          extra : meta
        }
      };

      rollbar.handleErrorWithPayloadData(msg, meta, logged);
    } else {
      rollbar.handleError(meta, logged);
    }
  } else {
    var payload = {
      level : level,
      custom : typeof meta === 'object' ? meta : {
        extra : meta
      }
    };

    rollbar.reportMessageWithPayloadData(msg, payload, null, logged);
  }
};
Example #11
0
 function * get(name, etag) {
   try {
     if (yield isEtagFresh(name, etag)) {
       return 304;
     }
     let pkg = yield fetchFromCache(name);
     if (pkg) return pkg;
     let end = metric.profile('npm.fetch', {
       'package': name
     });
     let opts = {
       timeout: config.timeout,
       headers: {}
     };
     if (etag) opts.headers['if-none-match'] = etag;
     let res = yield got(url.resolve(config.uplink.href, '/' + name.replace(/\//, '%2F')), opts);
     pkg = JSON.parse(res.body);
     pkg.etag = res.headers.etag;
     updateCache(pkg);
     end();
     return pkg;
   } catch (err) {
     switch (err.statusCode) {
       case 304:
         updateEtag(name, etag);
         return 304;
       case 404:
         return 404;
       default:
         if (config.rollbar) rollbar.handleError(err, {
           pkg: name,
           level: 'warning'
         });
         console.error(`error downloading ${name}: ${err}`);
         return 404;
     }
   }
 }
Example #12
0
 .catch(function(error) {
   console.log(error.stack);
   rollbar.handleError(error);
 });
Example #13
0
 .catch(function(err) {
   sails.log.error(format('%s: %s', self.communityName, err.message).red);
   rollbar.handleError(err);
 });