From d7c1f9a4ccfed0f1dbf664df235631b02463cd27 Mon Sep 17 00:00:00 2001 From: hrj Date: Sat, 2 Apr 2022 22:51:19 +0530 Subject: [PATCH] handle exceptions thrown by captcha provider --- src/main/scala/lc/core/captchaManager.scala | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/scala/lc/core/captchaManager.scala b/src/main/scala/lc/core/captchaManager.scala index 2df9c42..95a951c 100644 --- a/src/main/scala/lc/core/captchaManager.scala +++ b/src/main/scala/lc/core/captchaManager.scala @@ -34,13 +34,19 @@ class CaptchaManager(config: Config, captchaProviders: CaptchaProviders) { } def generateChallenge(param: Parameters): Option[Int] = { - captchaProviders.getProvider(param).flatMap { provider => - val providerId = provider.getId() - val challenge = provider.returnChallenge(param.level, param.size) - val blob = new ByteArrayInputStream(challenge.content) - val token = insertCaptcha(provider, challenge, providerId, param, blob) - // println("Added new challenge: " + token.toString) - token.map(_.toInt) + try { + captchaProviders.getProvider(param).flatMap { provider => + val providerId = provider.getId() + val challenge = provider.returnChallenge(param.level, param.size) + val blob = new ByteArrayInputStream(challenge.content) + val token = insertCaptcha(provider, challenge, providerId, param, blob) + // println("Added new challenge: " + token.toString) + token.map(_.toInt) + } + } catch { + case e: Exception => + e.printStackTrace() + None } }