added check for no claim and updated request error message with ip address

This commit is contained in:
bill bittner 2017-10-18 09:49:19 -07:00
parent 0a62df1d76
commit 607ca4d98c
5 changed files with 19 additions and 16 deletions

View file

@ -111,8 +111,7 @@ module.exports = {
logger.debug('getting asset by claim'); logger.debug('getting asset by claim');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.getLongClaimId(claimName, claimId) // 1. get the long claim id db.getLongClaimId(claimName, claimId) // 1. get the long claim id
// 2. get the claim Id .then(result => { // 2. get the asset using the long claim id
.then(result => {
if (result === NO_CLAIM || !result) { if (result === NO_CLAIM || !result) {
resolve(NO_CLAIM); resolve(NO_CLAIM);
return; return;
@ -129,18 +128,21 @@ module.exports = {
logger.debug('getting asset by channel'); logger.debug('getting asset by channel');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
db.getLongChannelId(channelName, channelId) // 1. get the long channel id db.getLongChannelId(channelName, channelId) // 1. get the long channel id
.then(result => { // 2. get the claim Id .then(result => { // 2. get the long claim Id
if (result === NO_CHANNEL) { if (result === NO_CHANNEL || !result) {
resolve(result); resolve(NO_CHANNEL);
return; return;
} }
return db.getClaimIdByLongChannelId(result, claimName); return db.getClaimIdByLongChannelId(result, claimName);
}) })
.then(result => { // 3. get the asset by this claim id and name .then(result => { // 3. get the asset using the long claim id
logger.debug('asset claim id =', result); logger.debug('asset claim id =', result);
if (result === NO_CHANNEL || result === NO_CLAIM) { if (result === NO_CHANNEL || result === NO_CLAIM) {
resolve(result); resolve(result);
return; return;
} else if (!result) {
resolve(NO_CLAIM);
return;
} }
resolve(getAssetByLongClaimId(result, claimName)); resolve(getAssetByLongClaimId(result, claimName));
}) })
@ -153,8 +155,7 @@ module.exports = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let longChannelId; let longChannelId;
let shortChannelId; let shortChannelId;
db db.getLongChannelId(channelName, channelId) // 1. get the long channel Id
.getLongChannelId(channelName, channelId) // 1. get the long channel Id
.then(result => { // 2. get all claims for that channel .then(result => { // 2. get all claims for that channel
if (result === NO_CHANNEL) { if (result === NO_CHANNEL) {
return NO_CHANNEL; return NO_CHANNEL;
@ -179,6 +180,7 @@ module.exports = {
const fileExtenstion = element.contentType.substring(element.contentType.lastIndexOf('/') + 1); const fileExtenstion = element.contentType.substring(element.contentType.lastIndexOf('/') + 1);
element['showUrlLong'] = `/${channelName}:${longChannelId}/${element.name}`; element['showUrlLong'] = `/${channelName}:${longChannelId}/${element.name}`;
element['directUrlLong'] = `/${channelName}:${longChannelId}/${element.name}.${fileExtenstion}`; element['directUrlLong'] = `/${channelName}:${longChannelId}/${element.name}.${fileExtenstion}`;
element['showUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}`;
element['directUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}.${fileExtenstion}`; element['directUrlShort'] = `/${channelName}:${shortChannelId}/${element.name}.${fileExtenstion}`;
element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL); element['thumbnail'] = chooseThumbnail(element, DEFAULT_THUMBNAIL);
}); });

View file

@ -3,7 +3,7 @@ const { postToStats } = require('../controllers/statsController.js');
module.exports = { module.exports = {
handleRequestError (action, originalUrl, ip, error, res) { handleRequestError (action, originalUrl, ip, error, res) {
logger.error('Request Error:', module.exports.useObjectPropertiesIfNoKeys(error)); logger.error(`Request Error: ${originalUrl}`, module.exports.useObjectPropertiesIfNoKeys(error));
postToStats(action, originalUrl, ip, null, null, error); postToStats(action, originalUrl, ip, null, null, error);
if (error.response) { if (error.response) {
res.status(error.response.status).send(error.response.data.error.message); res.status(error.response.status).send(error.response.data.error.message);

View file

@ -36,7 +36,7 @@ module.exports = (app) => {
}); });
}) })
.catch(error => { .catch(error => {
errorHandlers.handleRequestError(error, res); errorHandlers.handleRequestError(null, null, null, error, res);
}); });
}); });
// route to display a list of the trending images // route to display a list of the trending images
@ -49,7 +49,7 @@ module.exports = (app) => {
}); });
}) })
.catch(error => { .catch(error => {
errorHandlers.handleRequestError(error, res); errorHandlers.handleRequestError(null, null, null, error, res);
}); });
}); });
// route to show statistics for spee.ch // route to show statistics for spee.ch
@ -66,7 +66,7 @@ module.exports = (app) => {
}); });
}) })
.catch(error => { .catch(error => {
errorHandlers.handleRequestError(error, res); errorHandlers.handleRequestError(null, null, null, error, res);
}); });
}); });
// route to send embedable video player (for twitter) // route to send embedable video player (for twitter)

View file

@ -142,8 +142,8 @@ module.exports = (app) => {
getAsset(claimOrChannel, channelName, channelId, name, claimId) getAsset(claimOrChannel, channelName, channelId, name, claimId)
// 2. serve or show // 2. serve or show
.then(result => { .then(result => {
if (result === NO_CLAIM) { if (!result || result === NO_CLAIM) {
res.status(200).json({success: true, message: 'no matching claims were found'}); // res.status(200).render('noClaims'); res.status(200).json({success: true, message: 'no matching claims were found'});
return; return;
} else if (result === NO_CHANNEL) { } else if (result === NO_CHANNEL) {
res.status(200).json({success: true, message: 'no matching channel was found'}); res.status(200).json({success: true, message: 'no matching channel was found'});

View file

@ -1,14 +1,15 @@
<div class='row row--wide'> <div class='row row--wide'>
<div class="column column--3 align-content-top"> <div class="column column--3 align-content-top">
<a href="{{this.showUrlLong}}"><span class='content-list-card-link'></span></a> <a href="{{this.showUrlLong}}">
{{#ifConditional this.contentType '===' 'video/mp4'}} {{#ifConditional this.contentType '===' 'video/mp4'}}
<img class="content-list-item-asset" src="{{this.thumbnail}}"/> <img class="content-list-item-asset" src="{{this.thumbnail}}"/>
{{else}} {{else}}
<img class="content-list-item-asset" src="{{this.directUrlLong}}" /> <img class="content-list-item-asset" src="{{this.directUrlLong}}" />
{{/ifConditional}} {{/ifConditional}}
</a>
</div><div class="column column--7 align-content-top"> </div><div class="column column--7 align-content-top">
<p>{{this.title}}</p> <p>{{this.title}}</p>
<a href="{{this.directUrlShort}}">spee.ch{{this.directUrlShort}}</a> <a href="{{this.showUrlShort}}">spee.ch{{this.showUrlShort}}</a>
</div> </div>
</div> </div>