Skip to content

Commit

Permalink
[minor] Prefix console.error with primus: so people know it originate…
Browse files Browse the repository at this point in the history
…s from Primus

[minor] Added layer name to the deprecation warning so we know which middleware
[minor] Attempt to make a more generalised deperication warning.
  • Loading branch information
3rd-Eden committed Apr 6, 2014
1 parent 897c558 commit fa676f7
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions transformer.js
Expand Up @@ -94,8 +94,9 @@ Transformer.readable('initialise', function initialise() {
* @api private
*/
Transformer.readable('forEach', function forEach(type, req, res, next) {
var layers = this.primus.layers
, primus = this.primus;
var transformer = this
, layers = transformer.primus.layers
, primus = transformer.primus;

req.uri = req.uri || url(req.url, true);
req.query = req.query || req.uri.query || {};
Expand All @@ -107,7 +108,7 @@ Transformer.readable('forEach', function forEach(type, req, res, next) {

if (!layers.length) {
next();
return this;
return transformer;
}

//
Expand All @@ -128,14 +129,7 @@ Transformer.readable('forEach', function forEach(type, req, res, next) {
if (answered === false) {
answered = true;

if (!layer.warned) {
layer.warned = true;

var message = 'Returning `false` is deprecated and will execute ' +
'the next middleware in future releases.\nIf your middleware ' +
'has already answered the request you should return `true`.';
console.error(message);
}
if (!layer.warned) transformer.deprecate(layer);
}

if (answered) return;
Expand All @@ -149,7 +143,30 @@ Transformer.readable('forEach', function forEach(type, req, res, next) {
});
}(0));

return this;
return transformer;
});

/**
* Issue a deprecation warning.
*
* @param {String} data The object we're trying to deprecate.
* @api private
*/
Transformer.readable('deprecate', function deprecate(data) {
var name = data.name;

[
'',
'We\'ve detected that your middleware layer ('+ name +') is returning `false`',
'which will be deprecated in future releases. If this middleware has already',
'answered the request it should return `true`.',
''
].forEach(function each(line) {
console.error('primus: '+ line);
});

data.warned = true;
return data;
});

/**
Expand Down

0 comments on commit fa676f7

Please sign in to comment.