[requires] add tests for requires.io service, review error handling (#1361)

This commit is contained in:
chris48s
2018-01-03 03:13:10 +00:00
committed by Paul Melnikow
parent 503618443e
commit 9cb9d5984d
4 changed files with 100 additions and 6 deletions

23
lib/error-helper.js Normal file
View File

@@ -0,0 +1,23 @@
'use strict';
const checkErrorResponse = function(badgeData, err, res) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
badgeData.colorscheme = 'red';
return true;
} else if (res.statusCode === 404) {
badgeData.text[1] = 'not found';
badgeData.colorscheme = 'lightgrey';
return true;
} else if (res.statusCode !== 200) {
badgeData.text[1] = 'invalid';
badgeData.colorscheme = 'lightgrey';
return true;
} else {
return false;
}
};
module.exports = {
checkErrorResponse,
};