updated Claim model to return proper error if no matching claim id found

This commit is contained in:
bill bittner 2018-08-08 11:39:35 -07:00
parent 327db25f70
commit 764f4d4b6f
3 changed files with 21 additions and 19 deletions

View file

@ -36,7 +36,16 @@ const serverByIdentifierAndClaim = (req, res) => {
[claimId, claimName] = flipClaimNameAndId(claimId, claimName);
}
logger.debug('serve request:', { headers, ip, originalUrl, params });
logger.debug('serve request:', {
headers,
ip,
originalUrl,
params,
channelName,
channelClaimId,
claimName,
claimId,
});
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);

View file

@ -3,27 +3,19 @@ const logger = require('winston');
const db = require('../../models/index');
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
return new Promise((resolve, reject) => {
db.Certificate
.getLongChannelId(channelName, channelClaimId)
.then(longChannelId => {
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
})
.then(longClaimId => {
resolve(longClaimId);
})
.catch(error => {
reject(error);
});
});
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
return db.Certificate
.getLongChannelId(channelName, channelClaimId)
.then(longChannelId => {
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
});
};
const getClaimId = (channelName, channelClaimId, name, claimId) => {
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
if (channelName) {
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${name})`);
return getClaimIdByChannel(channelName, channelClaimId, name);
} else {
logger.debug(`db.Claim.getLongClaimId(${name}, ${claimId})`);
return db.Claim.getLongClaimId(name, claimId);
}
};

View file

@ -260,11 +260,11 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
.then(result => {
switch (result.length) {
case 0:
return resolve(null);
return reject(NO_CLAIM);
case 1:
return resolve(result[0].claimId);
default:
logger.error(`${result.length} records found for "${claimName}" in channel "${channelClaimId}"`);
logger.warn(`${result.length} records found for "${claimName}" in channel "${channelClaimId}"`);
return resolve(result[0].claimId);
}
})
@ -344,7 +344,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
};
Claim.getLongClaimId = function (claimName, claimId) {
// logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
if (isLongClaimId(claimId)) {
return this.validateLongClaimId(claimName, claimId);
} else if (isShortClaimId(claimId)) {
@ -379,6 +379,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
};
Claim.getOutpoint = function (name, claimId) {
logger.debug(`finding outpoint for ${name}#${claimId}`);
return this
.findAll({
where : { name, claimId },