# all files / raven-node/lib/middleware/ connect.js

64.29% Statements 9/14
100% Branches 2/2
25% Functions 1/4
64.29% Lines 9/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34

    1×
    1×

    1×

    1×

    2×

    1×

    1×

    1×

    1×
     'use strict';

    var Raven = require('../client');
    var utils = require('../utils');

    // Legacy support
    var connectMiddleware = function (client) {
      return connectMiddleware.errorHandler(client);
    };

    var getClient = function (clientOrDSN) {
      // Raven is an instance, so use Raven.constructor for instanceof check
      return clientOrDSN instanceof Raven.constructor ? clientOrDSN : new Raven.Client(clientOrDSN);
    };

    // Error handler. This should be the last item listed in middleware, but
    // before any other error handlers.
    connectMiddleware.errorHandler = function (clientOrDSN) {
      utils.consoleAlert('top-level Raven.middleware.errorHandler has been deprecated and will be removed in v2.0; use Raven.errorHandler() instance method instead');
      return getClient(clientOrDSN).errorHandler();
    };

    // Ensures asynchronous exceptions are routed to the errorHandler. This
    // should be the **first** item listed in middleware.
    connectMiddleware.requestHandler = function (clientOrDSN) {
      utils.consoleAlert('top-level Raven.middleware.requestHandler has been deprecated and will be removed in v2.0; use Raven.requestHandler() instance method instead');
      return getClient(clientOrDSN).requestHandler();
    };

    // for testing purposes only; not gonna worry about a nicer test exposure scheme since this code is going away soon
    connectMiddleware.getClient = getClient;

    module.exports = connectMiddleware;