Handling errors in email client better

This commit is contained in:
Collin Duncan 2023-08-10 13:33:49 +02:00
parent 714b1da735
commit fd5d059992
No known key found for this signature in database

View file

@ -9,6 +9,7 @@ import { Email } from './types'
export enum EmailClientStatus {
NotReady,
Ready,
Error,
}
@Injectable()
@ -205,16 +206,19 @@ export class EmailClient {
this.imapClient.on('close', () => {
this.loggerService.debug('email client close')
if (this.status !== EmailClientStatus.Error)
this.setStatus(EmailClientStatus.NotReady)
})
this.imapClient.on('end', () => {
this.loggerService.debug('email client end')
if (this.status !== EmailClientStatus.Error)
this.setStatus(EmailClientStatus.NotReady)
})
this.imapClient.on('error', (error: Error) => {
this.loggerService.error(`Error with imap client ${error.message}`)
this.setStatus(EmailClientStatus.Error)
})
}