Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
This commit is contained in:
@@ -1,52 +1,56 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const {
|
||||
NotFound,
|
||||
InvalidResponse,
|
||||
} = require('../services/errors');
|
||||
const { NotFound, InvalidResponse } = require('../services/errors')
|
||||
|
||||
const checkErrorResponse = function(badgeData, err, res, notFoundMessage = 'not found') {
|
||||
const checkErrorResponse = function(
|
||||
badgeData,
|
||||
err,
|
||||
res,
|
||||
notFoundMessage = 'not found'
|
||||
) {
|
||||
if (err != null) {
|
||||
badgeData.text[1] = 'inaccessible';
|
||||
badgeData.colorscheme = 'red';
|
||||
return true;
|
||||
badgeData.text[1] = 'inaccessible'
|
||||
badgeData.colorscheme = 'red'
|
||||
return true
|
||||
} else if (res.statusCode === 404) {
|
||||
badgeData.text[1] = notFoundMessage;
|
||||
badgeData.colorscheme = 'lightgrey';
|
||||
return true;
|
||||
badgeData.text[1] = notFoundMessage
|
||||
badgeData.colorscheme = 'lightgrey'
|
||||
return true
|
||||
} else if (res.statusCode !== 200) {
|
||||
badgeData.text[1] = 'invalid';
|
||||
badgeData.colorscheme = 'lightgrey';
|
||||
return true;
|
||||
badgeData.text[1] = 'invalid'
|
||||
badgeData.colorscheme = 'lightgrey'
|
||||
return true
|
||||
} else {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
checkErrorResponse.asPromise = function ({ notFoundMessage } = {}) {
|
||||
return async function ({ buffer, res }) {
|
||||
checkErrorResponse.asPromise = function({ notFoundMessage } = {}) {
|
||||
return async function({ buffer, res }) {
|
||||
if (res.statusCode === 404) {
|
||||
throw new NotFound({ prettyMessage: notFoundMessage });
|
||||
throw new NotFound({ prettyMessage: notFoundMessage })
|
||||
} else if (res.statusCode !== 200) {
|
||||
const underlying = Error(`Got status code ${res.statusCode} (expected 200)`);
|
||||
throw new InvalidResponse({ underlyingError: underlying});
|
||||
const underlying = Error(
|
||||
`Got status code ${res.statusCode} (expected 200)`
|
||||
)
|
||||
throw new InvalidResponse({ underlyingError: underlying })
|
||||
}
|
||||
return { buffer, res };
|
||||
};
|
||||
};
|
||||
return { buffer, res }
|
||||
}
|
||||
}
|
||||
|
||||
async function asJson({ buffer, res }) {
|
||||
try {
|
||||
return JSON.parse(buffer);
|
||||
return JSON.parse(buffer)
|
||||
} catch (err) {
|
||||
throw new InvalidResponse({
|
||||
prettyMessage: 'unparseable json response',
|
||||
underlyingError: err,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkErrorResponse,
|
||||
asJson,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user