Ben Irvin 13099b4c55 Send error status when token salt not set
Co-authored-by: Jean-Sébastien Herbaux <Convly@users.noreply.github.com>
2023-02-27 17:56:23 +01:00

27 lines
717 B
JavaScript

'use strict';
const { getService } = require('../utils');
module.exports = () => async (ctx, next) => {
const transferUtils = getService('transfer').utils;
const { hasValidTokenSalt, isDataTransferEnabled, isDisabledFromEnv } = transferUtils;
if (isDataTransferEnabled()) {
return next();
}
if (!hasValidTokenSalt()) {
return ctx.notImplemented(
'The server configuration for data transfer is invalid. Please contact your server administrator.'
);
}
if (isDisabledFromEnv()) {
return ctx.notFound();
}
// This should never happen as long as we're handling individual scenarios above
throw new Error('Unexpected error while trying to access a data transfer route');
};