Skip to content

Commit

Permalink
Provide more detailed info when the email search fails due to a timeo…
Browse files Browse the repository at this point in the history
…ut (#51)

* print search criteria to log on timeout

* provide more error details on search timeout

Co-authored-by: ryanrosello-og <[email protected]>
  • Loading branch information
ryanrosello-og and ryanrosello-og committed Jan 19, 2022
1 parent 88dcdb1 commit e615a96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/operations/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Messages {
if (((Date.now() - startTime) + delay) > options.timeout) {
return (options.errorOnTimeout === false) ?
resolve(body) :
reject(new MailosaurError('No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this).', 'search_timeout'));
reject(new MailosaurError(`No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this). The search criteria used for this query was [${JSON.stringify(criteria)}] which timed out after ${options.timeout}ms`, 'search_timeout'));
}

return setTimeout(fn(resolve, reject), delay);
Expand Down
15 changes: 15 additions & 0 deletions test/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ describe('emails', () => {
});
});

it('should throw a meaningful error if the timeout is reached', (done) => {
const testFromEmail = '[email protected]';
client.messages
.search(server, {
sentFrom: testFromEmail
}, {
timeout: 1,
})
.catch((err) => {
assert.instanceOf(err, MailosaurError);
assert.equal(err.message, `No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this). The search criteria used for this query was [{"sentFrom":"${testFromEmail}"}] which timed out after 1ms`);
done();
});
});

it('should return empty array if errors suppressed', (done) => {
client.messages.search(server, {
sentTo: '[email protected]'
Expand Down

0 comments on commit e615a96

Please sign in to comment.