Created
October 11, 2022 08:48
-
-
Save PonomareVlad/ed002cd73f3722d6bf004e7aa5b2cfac to your computer and use it in GitHub Desktop.
Telebot error handling case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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