mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
1fd155d56a
- identified by tsc, this shouldn't change any functionality because there were extra arguments being supplied and were unused
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const extractApiKey = require('@tryghost/extract-api-key');
|
|
|
|
const versionMismatchHandler = (APIVersionCompatibilityService) => {
|
|
/**
|
|
* @param {Object} err
|
|
* @param {import('express').Request} req
|
|
* @param {import('express').Response} res
|
|
* @param {import('express').NextFunction} next
|
|
*/
|
|
return async function versionMismatchHandlerMiddleware(err, req, res, next) {
|
|
if (err && err.errorType === 'RequestNotAcceptableError') {
|
|
if (err.code === 'UPDATE_CLIENT') {
|
|
const {key, type} = extractApiKey(req);
|
|
const requestURL = req.originalUrl.split('?').shift();
|
|
|
|
await APIVersionCompatibilityService.handleMismatch({
|
|
acceptVersion: req.headers['accept-version'],
|
|
contentVersion: `v${res.locals.safeVersion}`,
|
|
requestURL,
|
|
userAgent: req.headers['user-agent'],
|
|
apiKeyValue: key,
|
|
apiKeyType: type
|
|
});
|
|
}
|
|
}
|
|
|
|
next(err);
|
|
};
|
|
};
|
|
|
|
module.exports = versionMismatchHandler;
|