This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix middleware backwards compatibility (#246)
* Fix middleware `client instanceof Raven.Client` check to use `Raven.constructor` (thanks @dhritzkiv) * Add deprecation warning to top-level middleware * Add tests for top-level Raven.middleware backwards compat
- Loading branch information
1 parent
70a196f
commit 88f4fde
Showing
2 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
'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 (client) { | ||
client = client instanceof Raven.Client ? client : new Raven.Client(client); | ||
return client.errorHandler(); | ||
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 (client) { | ||
client = client instanceof Raven.Client ? client : new Raven.Client(client); | ||
return client.requestHandler(); | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters