Created
July 22, 2014 20:57
-
-
Save makishvili/8a1c5db63a4f6c5e2be6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var inherit = require('inherit'); | |
/** | |
* Asker error. | |
* | |
* @param {Error} e Terror instance. | |
* @param {Object} askerConfig Params for asker which were used for this very breaked request | |
* @param {String} message Optional human-readable description of the error. | |
*/ | |
var AskError = inherit(Error, { | |
__constructor: function (e, askerConfig, message) { | |
// Copy all fields of Terror to AskError | |
Object.keys(e).forEach(function (key) { | |
this[key] = e[key]; | |
}.bind(this)); | |
// Add anvice for curl-ing | |
this.advice = this._makeAdvice(askerConfig); | |
console.log(this); | |
Error.captureStackTrace(this, this.constructor); | |
}, | |
_makeAdvice: function (askerConfig) { | |
var req = askerConfig; | |
var url = req.protocol + '//' + req.host + ':' + req.port + req.path; | |
var curl = 'curl %data% -v -X ' + req.method + ' -H "Content-Type: application/json" -H "Host: ' + req.headers.Host + '" "'+ url +'"'; | |
var data = ''; | |
if (req.method === 'POST' && req.body) { | |
// получить ПОСТ-данные, обратить в строку, подставить | |
// --data '{"id": 155289153}' | |
data = '--data \'{\'}'; | |
} | |
curl = curl.replace('%data%', data); | |
return [ | |
'Если ошибка повторяется, попробуйте её воспроизвести другим способом. Скопируйте и выполните в терминале:', | |
curl | |
]; | |
} | |
}); | |
module.exports = AskError; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment