refactor error messages for unavailable content
This commit is contained in:
parent
0a74e50167
commit
208c56366f
3 changed files with 7 additions and 8 deletions
|
@ -21,7 +21,7 @@ const channelData = ({ ip, originalUrl, body, params }, res) => {
|
|||
if (serveOnlyApproved && !isApprovedChannel(chanObj)) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'This spee.ch instance serves limited content which does not include this asset',
|
||||
message: 'This content is unavailable',
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ const NO_CHANNEL = 'NO_CHANNEL';
|
|||
const NO_CLAIM = 'NO_CLAIM';
|
||||
const BLOCKED_CLAIM = 'BLOCKED_CLAIM';
|
||||
const NO_FILE = 'NO_FILE';
|
||||
const UNAPPROVED_CHANNEL = 'UNAPPROVED_CHANNEL';
|
||||
const CONTENT_UNAVAILABLE = 'CONTENT_UNAVAILABLE';
|
||||
|
||||
const { publishing: { serveOnlyApproved } } = require('@config/siteConfig');
|
||||
|
||||
|
@ -30,7 +30,7 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
|
|||
})
|
||||
.then(claim => {
|
||||
if (serveOnlyApproved && !isApprovedChannel({ longId: claim.dataValues.certificateId })) {
|
||||
throw new Error(UNAPPROVED_CHANNEL);
|
||||
throw new Error(CONTENT_UNAVAILABLE);
|
||||
}
|
||||
logger.debug('Outpoint:', claim.dataValues.outpoint);
|
||||
return db.Blocked.isNotBlocked(claim.dataValues.outpoint);
|
||||
|
@ -64,11 +64,11 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
|
|||
message: 'No matching channel id could be found for that url',
|
||||
});
|
||||
}
|
||||
if (error === UNAPPROVED_CHANNEL) {
|
||||
if (error === CONTENT_UNAVAILABLE) {
|
||||
logger.debug('unapproved channel');
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'This spee.ch instance serves limited content which does not include this asset',
|
||||
message: 'This content is unavailable',
|
||||
});
|
||||
}
|
||||
if (error === BLOCKED_CLAIM) {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
const logger = require('winston');
|
||||
const returnShortId = require('./utils/returnShortId.js');
|
||||
const isApprovedChannel = require('../utils/isApprovedChannel');
|
||||
const { assetDefaults: { thumbnail: defaultThumbnail }, details: { host } } = require('@config/siteConfig');
|
||||
const { publishing: { serveOnlyApproved } } = require('@config/siteConfig');
|
||||
const isApprovedChannel = require('../utils/isApprovedChannel');
|
||||
|
||||
const NO_CLAIM = 'NO_CLAIM';
|
||||
const NOT_ALLOWED = 'NOT_ALLOWED';
|
||||
|
||||
function determineFileExtensionFromContentType (contentType) {
|
||||
switch (contentType) {
|
||||
|
@ -366,7 +365,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
|||
})
|
||||
.then(claimArray => {
|
||||
if (serveOnlyApproved && !isApprovedChannel({ longId: claimArray[0].dataValues.certificateId })) {
|
||||
reject(NOT_ALLOWED);
|
||||
reject('This content is unavailable');
|
||||
}
|
||||
switch (claimArray.length) {
|
||||
case 0:
|
||||
|
|
Loading…
Reference in a new issue