11/*
2- * Copyright 1998-2024 Linux.org.ru
2+ * Copyright 1998-2026 Linux.org.ru
33 * Licensed under the Apache License, Version 2.0 (the "License");
44 * you may not use this file except in compliance with the License.
55 * You may obtain a copy of the License at
@@ -21,33 +21,37 @@ import org.springframework.context.annotation.{Bean, Configuration}
2121import org .springframework .scheduling .TaskScheduler
2222import org .springframework .scheduling .concurrent .ConcurrentTaskScheduler
2323import ru .org .linux .spring .SiteConfig
24+ import sttp .client4 .SttpClientException
2425
2526import java .io .{PrintWriter , StringWriter }
2627import java .util .concurrent .Executors
2728
2829@ Configuration
29- class ExceptionHandlingConfiguration extends StrictLogging {
30- @ Bean (name= Array (" exceptionMailingActor" ))
31- def exceptionMailingActor (siteConfig : SiteConfig , actorSystem : ActorSystem ): ActorRef = {
30+ class ExceptionHandlingConfiguration extends StrictLogging :
31+ @ Bean (name = Array (" exceptionMailingActor" ))
32+ def exceptionMailingActor (siteConfig : SiteConfig , actorSystem : ActorSystem ): ActorRef =
3233 actorSystem.actorOf(ExceptionMailingActor .props(siteConfig))
33- }
3434
3535 @ Bean
36- def taskScheduler (exceptionMailingActor : ActorRef ): TaskScheduler = {
36+ def taskScheduler (exceptionMailingActor : ActorRef ): TaskScheduler =
3737 val scheduler = new ConcurrentTaskScheduler (Executors .newSingleThreadScheduledExecutor)
3838
39- scheduler.setErrorHandler(ex => {
39+ scheduler.setErrorHandler(ex =>
4040 val text = new StringBuilder (" Periodic task failed\n\n " )
4141
42+ val cleanException =
43+ ex match
44+ case e : SttpClientException =>
45+ e.cause
46+ case other =>
47+ other
48+
4249 val exceptionStackTrace = new StringWriter
43- ex .printStackTrace(new PrintWriter (exceptionStackTrace))
50+ cleanException .printStackTrace(new PrintWriter (exceptionStackTrace))
4451 text.append(exceptionStackTrace.toString)
4552
46- logger.warn(" Periodic task failed" , ex )
53+ logger.warn(" Periodic task failed" , cleanException )
4754
48- exceptionMailingActor ! ExceptionMailingActor .Report (ex.getClass, text.toString())
49- })
55+ exceptionMailingActor ! ExceptionMailingActor .Report (cleanException.getClass, cleanException.toString()))
5056
5157 scheduler
52- }
53- }
0 commit comments