updated Claim model to return proper error if no matching claim id found
This commit is contained in:
parent
327db25f70
commit
764f4d4b6f
3 changed files with 21 additions and 19 deletions
|
@ -36,7 +36,16 @@ const serverByIdentifierAndClaim = (req, res) => {
|
||||||
[claimId, claimName] = flipClaimNameAndId(claimId, claimName);
|
[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);
|
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
|
||||||
|
|
||||||
|
|
|
@ -3,27 +3,19 @@ const logger = require('winston');
|
||||||
const db = require('../../models/index');
|
const db = require('../../models/index');
|
||||||
|
|
||||||
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
|
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
|
||||||
return new Promise((resolve, reject) => {
|
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
|
||||||
db.Certificate
|
return db.Certificate
|
||||||
.getLongChannelId(channelName, channelClaimId)
|
.getLongChannelId(channelName, channelClaimId)
|
||||||
.then(longChannelId => {
|
.then(longChannelId => {
|
||||||
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
|
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
|
||||||
})
|
|
||||||
.then(longClaimId => {
|
|
||||||
resolve(longClaimId);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getClaimId = (channelName, channelClaimId, name, claimId) => {
|
const getClaimId = (channelName, channelClaimId, name, claimId) => {
|
||||||
|
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
|
||||||
if (channelName) {
|
if (channelName) {
|
||||||
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${name})`);
|
|
||||||
return getClaimIdByChannel(channelName, channelClaimId, name);
|
return getClaimIdByChannel(channelName, channelClaimId, name);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`db.Claim.getLongClaimId(${name}, ${claimId})`);
|
|
||||||
return db.Claim.getLongClaimId(name, claimId);
|
return db.Claim.getLongClaimId(name, claimId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -260,11 +260,11 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
.then(result => {
|
.then(result => {
|
||||||
switch (result.length) {
|
switch (result.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return resolve(null);
|
return reject(NO_CLAIM);
|
||||||
case 1:
|
case 1:
|
||||||
return resolve(result[0].claimId);
|
return resolve(result[0].claimId);
|
||||||
default:
|
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);
|
return resolve(result[0].claimId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -344,7 +344,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
Claim.getLongClaimId = function (claimName, claimId) {
|
Claim.getLongClaimId = function (claimName, claimId) {
|
||||||
// logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
|
logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
|
||||||
if (isLongClaimId(claimId)) {
|
if (isLongClaimId(claimId)) {
|
||||||
return this.validateLongClaimId(claimName, claimId);
|
return this.validateLongClaimId(claimName, claimId);
|
||||||
} else if (isShortClaimId(claimId)) {
|
} else if (isShortClaimId(claimId)) {
|
||||||
|
@ -379,6 +379,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
Claim.getOutpoint = function (name, claimId) {
|
Claim.getOutpoint = function (name, claimId) {
|
||||||
|
logger.debug(`finding outpoint for ${name}#${claimId}`);
|
||||||
return this
|
return this
|
||||||
.findAll({
|
.findAll({
|
||||||
where : { name, claimId },
|
where : { name, claimId },
|
||||||
|
|
Loading…
Reference in a new issue