4873303658
refs https://github.com/TryGhost/Toolbox/issues/292 - This middleware is meant to deal with version missmatch erros and call a service that does all the business logic. Having this handling in a separate module allows for thisngs to be loosely coupled
18 lines
614 B
JavaScript
18 lines
614 B
JavaScript
const versionMismatchHandler = (APIVersionCompatibilityService) => {
|
|
return async (err, req, res, next) => {
|
|
if (err && err.errorType === 'RequestNotAcceptableError') {
|
|
if (err.code === 'UPDATE_CLIENT') {
|
|
await APIVersionCompatibilityService.handleMismatch({
|
|
acceptVersion: req.headers['accept-version'],
|
|
contentVersion: `v${res.locals.safeVersion}`,
|
|
userAgent: req.headers['user-agent']
|
|
});
|
|
}
|
|
}
|
|
|
|
next(err, req, res);
|
|
};
|
|
};
|
|
|
|
module.exports = versionMismatchHandler;
|