diff --git a/lib/bot/middleware/oniotmessage.js b/lib/bot/middleware/oniotmessage.js index b20aaf819..c68d0b151 100644 --- a/lib/bot/middleware/oniotmessage.js +++ b/lib/bot/middleware/oniotmessage.js @@ -90,7 +90,7 @@ exports.createErrorHandler = (lambda, opts) => { if (error instanceof Errors.TimeTravel) { logMsg = 'rejecting message with lower timestamp than previous'; } - else if (error instanceof Errors.NotFound) { + else if (error instanceof Errors.NotFound || error instanceof Errors.UnknownAuthor) { logMsg = 'rejecting message, either sender or payload identity was not found'; } else if (error instanceof Errors.InvalidMessageFormat) { diff --git a/lib/errors.js b/lib/errors.js index ce77d6bca..72ef378a6 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -97,6 +97,7 @@ const errors = { NotFound: createError('NotFound'), InvalidSignature: createError('InvalidSignature'), InvalidAuthor: createError('InvalidAuthor'), + UnknownAuthor: createError('UnknownAuthor'), InvalidVersion: createError('InvalidVersion'), InvalidMessageFormat: createError('InvalidMessageFormat'), PutFailed: createError('PutFailed'), diff --git a/lib/identities.js b/lib/identities.js index 634303cb1..034b1723c 100644 --- a/lib/identities.js +++ b/lib/identities.js @@ -22,10 +22,16 @@ class Identities { constructor(opts) { this.metaByPub = (pub) => __awaiter(this, void 0, void 0, function* () { this.logger.debug('get identity metadata by pub', pub); - return this.pubKeys.get({ - Key: { pub }, - ConsistentRead: true - }); + try { + return yield this.pubKeys.get({ + Key: { pub }, + ConsistentRead: true + }); + } + catch (err) { + Errors.ignore(err, Errors.NotFound); + throw new Errors.UnknownAuthor(`with pub: ${pub}`); + } }); this.byPub = (pub) => __awaiter(this, void 0, void 0, function* () { const { link } = yield this.metaByPub(pub); @@ -37,7 +43,7 @@ class Identities { pub, error: err.stack }); - throw new NotFound('identity with pub: ' + pub); + throw new Errors.UnknownAuthor('with pub: ' + pub); } }); this.byPermalink = (permalink) => __awaiter(this, void 0, void 0, function* () { diff --git a/src/bot/middleware/oniotmessage.ts b/src/bot/middleware/oniotmessage.ts index 8455ca42c..502a0a3b0 100644 --- a/src/bot/middleware/oniotmessage.ts +++ b/src/bot/middleware/oniotmessage.ts @@ -99,7 +99,7 @@ export const createErrorHandler = (lambda, opts) => { if (error instanceof Errors.TimeTravel) { logMsg = 'rejecting message with lower timestamp than previous' // @ts-ignore - } else if (error instanceof Errors.NotFound) { + } else if (error instanceof Errors.NotFound || error instanceof Errors.UnknownAuthor) { logMsg = 'rejecting message, either sender or payload identity was not found' // @ts-ignore } else if (error instanceof Errors.InvalidMessageFormat) { diff --git a/src/errors.ts b/src/errors.ts index 77688191f..9467fc6d7 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -123,6 +123,7 @@ const errors = { NotFound: createError('NotFound'), InvalidSignature: createError('InvalidSignature'), InvalidAuthor: createError('InvalidAuthor'), + UnknownAuthor: createError('UnknownAuthor'), InvalidVersion: createError('InvalidVersion'), InvalidMessageFormat: createError('InvalidMessageFormat'), PutFailed: createError('PutFailed'), diff --git a/src/identities.ts b/src/identities.ts index cd8cf6ee7..73e676863 100644 --- a/src/identities.ts +++ b/src/identities.ts @@ -44,10 +44,15 @@ export default class Identities { public metaByPub = async (pub:string) => { this.logger.debug('get identity metadata by pub', pub) - return this.pubKeys.get({ - Key: { pub }, - ConsistentRead: true - }) + try { + return await this.pubKeys.get({ + Key: { pub }, + ConsistentRead: true + }) + } catch (err) { + Errors.ignore(err, Errors.NotFound) + throw new Errors.UnknownAuthor(`with pub: ${pub}`) + } } public byPub = async (pub:string):Promise => { @@ -60,7 +65,7 @@ export default class Identities { error: err.stack }) - throw new NotFound('identity with pub: ' + pub) + throw new Errors.UnknownAuthor('with pub: ' + pub) } }