add err handler for UpdateListener

- add err handler for UpdateListener in MornyCoeur
  - for network-related exception, will only output exception basic message and not report.
  - for other type of exception, will output all message of exception and do report.
- Scheduler's runnerName now is `$classBaseName@$hashCode`
This commit is contained in:
A.C.Sukazyo Eyre 2023-11-16 20:06:15 +08:00
parent 2c30b5ec09
commit 720771719e
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
3 changed files with 41 additions and 6 deletions

View File

@ -5,12 +5,12 @@ MORNY_ARCHIVE_NAME = morny-coeur
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
VERSION = 1.3.0-dev3 VERSION = 1.3.0-dev4
USE_DELTA = false USE_DELTA = false
VERSION_DELTA = VERSION_DELTA =
CODENAME = xiongan CODENAME = guanggu
# dependencies # dependencies

View File

@ -96,7 +96,42 @@ class MornyCoeur (using val config: MornyConfig) {
daemons.start() daemons.start()
logger info "start telegram event listening" logger info "start telegram event listening"
account setUpdatesListener eventManager import com.pengrad.telegrambot.TelegramException
account.setUpdatesListener(eventManager, (e: TelegramException) => {
if (e.response != null) {
import com.google.gson.GsonBuilder
logger error
s"""Failed get updates: ${e.getMessage}
| server responses:
|${GsonBuilder().setPrettyPrinting().create.toJson(e.response) indent 4}
|""".stripMargin
}
if (e.getCause != null) {
import java.net.{SocketException, SocketTimeoutException}
import javax.net.ssl.SSLHandshakeException
val caused = e.getCause
caused match
case e_timeout: (SSLHandshakeException|SocketException|SocketTimeoutException) =>
import cc.sukazyo.messiva.log.Message
import scala.collection.mutable
val log = mutable.ArrayBuffer(s"Failed get updates: Network Error")
var current: Throwable = e_timeout
log += s" due to: ${current.getMessage}"
while (current.getCause != null) {
current = current.getCause
log += s" caused by: ${current.getClass.getSimpleName}: ${current.getMessage}"
}
logger error Message(log mkString "\n")
case e_other =>
logger error exceptionLog(e_other)
this.daemons.reporter exception e_other
}
})
if config.commandLoginRefresh then if config.commandLoginRefresh then
logger info "resetting telegram command list" logger info "resetting telegram command list"
commands.automaticTGListUpdate() commands.automaticTGListUpdate()

View File

@ -141,7 +141,7 @@ class Scheduler {
*/ */
//noinspection ScalaWeakerAccess //noinspection ScalaWeakerAccess
def runnerName: String = def runnerName: String =
this.toString s"${this.getClass.getSimpleName}@${this.hashCode.toHexString}"
/** Add one task to scheduler task queue. /** Add one task to scheduler task queue.
* @return this scheduler for chained call. * @return this scheduler for chained call.