-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from featurist/es5-check
fix es5 compat issues, add es5 check
- Loading branch information
Showing
7 changed files
with
641 additions
and
58 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
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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var middleware = require('./middleware') | ||
var exceptionMiddleware = require('./exception')() | ||
|
||
module.exports = middleware('exception', exceptionMiddleware) |
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,26 +1,29 @@ | ||
var middleware = require('./middleware') | ||
var extend = require('../extend') | ||
var obfuscateUrlPassword = require('../obfuscateUrlPassword') | ||
var logError = require('debug')('httpism:error') | ||
var prepareForLogging = require('./prepareForLogging') | ||
var logDetailError = require('debug')('httpism:response:error') | ||
|
||
module.exports = middleware('exception', function (request, next) { | ||
return next().then(function (response) { | ||
var exceptions = request.options.exceptions | ||
var isException = exceptions === false ? false : typeof exceptions === 'function' ? exceptions(response) : response.statusCode >= 400 | ||
module.exports = function (logError, logDetailError) { | ||
return function (request, next) { | ||
return next().then(function (response) { | ||
var exceptions = request.options.exceptions | ||
var isException = exceptions === false ? false : typeof exceptions === 'function' ? exceptions(response) : response.statusCode >= 400 | ||
|
||
if (isException) { | ||
var obfuscatedUrl = obfuscateUrlPassword(request.url) | ||
var msg = request.method.toUpperCase() + ' ' + obfuscatedUrl + ' => ' + response.statusCode + ' ' + response.statusText | ||
logError(msg) | ||
var logResponse = prepareForLogging(response) | ||
logDetailError(logResponse) | ||
var error = extend(new Error(msg), response) | ||
error.url = obfuscatedUrl | ||
throw error | ||
} else { | ||
return response | ||
} | ||
}) | ||
}) | ||
if (isException) { | ||
var obfuscatedUrl = obfuscateUrlPassword(request.url) | ||
var msg = request.method.toUpperCase() + ' ' + obfuscatedUrl + ' => ' + response.statusCode + ' ' + response.statusText | ||
if (logError) { | ||
logError(msg) | ||
} | ||
var logResponse = prepareForLogging(response) | ||
if (logDetailError) { | ||
logDetailError(logResponse) | ||
} | ||
var error = extend(new Error(msg), response) | ||
error.url = obfuscatedUrl | ||
throw error | ||
} else { | ||
return response | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var middleware = require('./middleware') | ||
var logError = require('debug')('httpism:error') | ||
var logDetailError = require('debug')('httpism:response:error') | ||
var exceptionMiddleware = require('./exception')(logError, logDetailError) | ||
|
||
module.exports = middleware('exception', exceptionMiddleware) |
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
Oops, something went wrong.