Browse Source

treat 404's from placeholder the same as other errors

pull/850/head
Stephen Hess 8 years ago
parent
commit
0adc76eca6
  1. 8
      service/placeholder.js
  2. 14
      test/unit/service/placeholder.js

8
service/placeholder.js

@ -37,14 +37,8 @@ module.exports = function setup(url) {
return callback(`${encodeURI(requestUrl)} could not parse response: ${data}`);
}
}
else if (response.statusCode === 404) {
// placeholder returns a 404 when no results are found which
// should be handled differently since it's technically not an error
logger.debug(`returned 0 results for '${text}'`);
return callback(null, []);
}
else {
// otherwise there was a non-200/404 status so handle generically
// otherwise there was a non-200 status so handle generically
logger.error(`${encodeURI(requestUrl)} returned status ${response.statusCode}: ${data}`);
return callback(`${encodeURI(requestUrl)} returned status ${response.statusCode}: ${data}`);
}

14
test/unit/service/placeholder.js

@ -64,7 +64,7 @@ module.exports.tests.failure_conditions = (test, common) => {
});
test('server returning non-200/404 response should log error and return no results', (t) => {
test('server returning non-200 response should log error and return no results', (t) => {
const placeholderServer = express();
placeholderServer.get('/search', (req, res, next) => {
res.status(400).send('a bad request was made');
@ -92,10 +92,11 @@ module.exports.tests.failure_conditions = (test, common) => {
});
test('server returning 404 statusCode should log debug message and return no error or results', (t) => {
test('server returning 404 statusCode should be treated the same as other statusCodes', (t) => {
// at one point placeholder treated 0 results as a 404 instead of just an unparseable input
const placeholderServer = express();
placeholderServer.get('/search', (req, res, next) => {
res.status(404).send('no results found');
res.status(404).send('resource not found');
});
const server = placeholderServer.listen();
@ -108,9 +109,10 @@ module.exports.tests.failure_conditions = (test, common) => {
})(`http://localhost:${port}`);
service.search('search text', 'search lang', (err, results) => {
t.notOk(err);
t.deepEquals(results, [], 'should return an empty array');
t.ok(logger.isDebugMessage('returned 0 results for \'search text\''));
t.equals(err, `http://localhost:${port}/search?text=search%20text&lang=search%20lang returned status 404: resource not found`);
t.notOk(results);
t.ok(logger.isErrorMessage(`http://localhost:${port}/search?text=search%20text&lang=search%20lang ` +
`returned status 404: resource not found`));
t.end();
server.close();

Loading…
Cancel
Save