Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
function stripToken(str) { | ||
if (typeof str !== 'string') return str; | ||
return str.replace(/access_token=[^& ]+/, 'access_token=...'); | ||
} | ||
|
||
/** | ||
* Sanitize superagent error objects | ||
* | ||
* @private | ||
* @param {object} err an error object received from a superagent HTTP request | ||
* @returns {object} a sanitized representation of the HTTP error | ||
*/ | ||
module.exports = function(err) { | ||
if (!err) return null; | ||
if (!err.response || !err.response.error) return err; | ||
var error = err.response.error; | ||
if (typeof error !== 'object') return err; | ||
error.message = stripToken(error.message || 'Unknown Error'); | ||
Object.keys(error).forEach(function(key) { | ||
error[key] = stripToken(error[key]); | ||
}); | ||
return error; | ||
}; |
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
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