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

View file

@ -3,7 +3,7 @@ const { postToStats } = require('../controllers/statsController.js');
module.exports = {
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);
if (error.response) {
res.status(error.response.status).send(error.response.data.error.message);

View file

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

View file

@ -142,8 +142,8 @@ module.exports = (app) => {
getAsset(claimOrChannel, channelName, channelId, name, claimId)
// 2. serve or show
.then(result => {
if (result === NO_CLAIM) {
res.status(200).json({success: true, message: 'no matching claims were found'}); // res.status(200).render('noClaims');
if (!result || result === NO_CLAIM) {
res.status(200).json({success: true, message: 'no matching claims were found'});
return;
} else if (result === NO_CHANNEL) {
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="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'}}
<img class="content-list-item-asset" src="{{this.thumbnail}}"/>
{{else}}
<img class="content-list-item-asset" src="{{this.directUrlLong}}" />
{{/ifConditional}}
</a>
</div><div class="column column--7 align-content-top">
<p>{{this.title}}</p>
<a href="{{this.directUrlShort}}">spee.ch{{this.directUrlShort}}</a>
<a href="{{this.showUrlShort}}">spee.ch{{this.showUrlShort}}</a>
</div>
</div>