From 239bf2cefc46d0a019578f6696542ac0bf8d5fe5 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 3 Jul 2020 22:16:23 +0530 Subject: [PATCH] gracefully handle wrong input from API --- src/main/scala/lc/Main.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/scala/lc/Main.scala b/src/main/scala/lc/Main.scala index eef209e..c2b98ae 100644 --- a/src/main/scala/lc/Main.scala +++ b/src/main/scala/lc/Main.scala @@ -110,10 +110,13 @@ class Captcha(throttle: Int) extends DBConn { def checkAnswer(answer: Answer): Boolean = { selectPstmt.setString(1, answer.id) val rs: ResultSet = selectPstmt.executeQuery() - rs.next() - val secret = rs.getString("secret") - val provider = rs.getString("provider") - providers(provider).checkAnswer(secret, answer.answer) + if (rs.first()) { + val secret = rs.getString("secret") + val provider = rs.getString("provider") + providers(provider).checkAnswer(secret, answer.answer) + } else { + false + } } def getHash(email: String): Int = {