Handling errors in email client better
This commit is contained in:
parent
714b1da735
commit
fd5d059992
1 changed files with 6 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ import { Email } from './types'
|
||||||
export enum EmailClientStatus {
|
export enum EmailClientStatus {
|
||||||
NotReady,
|
NotReady,
|
||||||
Ready,
|
Ready,
|
||||||
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -205,16 +206,19 @@ export class EmailClient {
|
||||||
|
|
||||||
this.imapClient.on('close', () => {
|
this.imapClient.on('close', () => {
|
||||||
this.loggerService.debug('email client close')
|
this.loggerService.debug('email client close')
|
||||||
|
if (this.status !== EmailClientStatus.Error)
|
||||||
this.setStatus(EmailClientStatus.NotReady)
|
this.setStatus(EmailClientStatus.NotReady)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.imapClient.on('end', () => {
|
this.imapClient.on('end', () => {
|
||||||
this.loggerService.debug('email client end')
|
this.loggerService.debug('email client end')
|
||||||
|
if (this.status !== EmailClientStatus.Error)
|
||||||
this.setStatus(EmailClientStatus.NotReady)
|
this.setStatus(EmailClientStatus.NotReady)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.imapClient.on('error', (error: Error) => {
|
this.imapClient.on('error', (error: Error) => {
|
||||||
this.loggerService.error(`Error with imap client ${error.message}`)
|
this.loggerService.error(`Error with imap client ${error.message}`)
|
||||||
|
this.setStatus(EmailClientStatus.Error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue