Skip to content

Commit

Permalink
Treat non-ok HTTP status codes as separate error from redirect chain,…
Browse files Browse the repository at this point in the history
… and treat redirect chains starting with a 302 as valid
  • Loading branch information
Munter committed Apr 11, 2015
1 parent b5b619e commit 5f430d3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ module.exports = function (options) {
redirects = redirects || [];
relations = relations || [];

if (status !== 200) {
var invalidStatusReport = {
ok: false,
name: 'should respond with HTTP status 200',
operator: 'error',
expected: [200, url].join(' '),
actual: [status, url].join(' '),
at: _.uniq(relations.map(function (relation) {
return relation.from.urlOrDescription.replace(/#.*$/, '');
})).join('\n ')
};

errorCount += 1;
t.push(null, invalidStatusReport);
}

var report = {
ok: true,
name: 'URI should have no redirects - ' + url,
Expand All @@ -54,16 +70,13 @@ module.exports = function (options) {
return [redirect.statusCode, redirect.redirectUri].join(' ');
}).join(' --> ');

report.ok = false;
report.actual = logLine;
} else {
report.actual = [status, url].join(' ');

if (status !== 200) {
if (log[0].statusCode !== 302) {
report.ok = false;
report.name = 'should respond with HTTP status 200';
report.operator = 'error';
}
} else {
report.actual = [status, url].join(' ');
}

if (!report.ok) {
Expand Down

0 comments on commit 5f430d3

Please sign in to comment.