Skip to content

Instantly share code, notes, and snippets.

@PonomareVlad
Created October 11, 2022 08:48
Show Gist options
  • Save PonomareVlad/ed002cd73f3722d6bf004e7aa5b2cfac to your computer and use it in GitHub Desktop.
Save PonomareVlad/ed002cd73f3722d6bf004e7aa5b2cfac to your computer and use it in GitHub Desktop.
Telebot error handling case
const handleError = async error => {
console.error(error)
this.log.push(error)
try {
switch (error.error_code) {
case 429:
this.abort = true;
console.debug('Task reverted', await this.updateTask(this.task, {status: 'new'}))
break;
default:
switch (error.description) {
case 'Bad Request: chat not found':
case 'Forbidden: user is deactivated':
case 'Forbidden: bot was blocked by the user':
console.debug('Subscriber paused', await (await new Subscriber({id: this?.task?.subscriber})).set('state', 'paused'))
await this.deleteTask(this.task)
break;
default:
await this.updateTask(this.task, {status: 'error', error: serializeError(error)})
break;
}
}
} catch (e) {
console.error(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment