From 116a7c818d56d19cd4b9bce0ccabf7a2daa7c7a8 Mon Sep 17 00:00:00 2001 From: hongwei Date: Tue, 10 Oct 2023 12:52:47 +0200 Subject: [PATCH] refactor/catch the exception and check the error instead of check connection status --- .../src/main/scala/bootstrap/liftweb/Boot.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala index dfea714a39..a3b9dc7e9d 100644 --- a/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala +++ b/obp-api/src/main/scala/bootstrap/liftweb/Boot.scala @@ -703,13 +703,13 @@ class Boot extends MdcLoggable { }) LiftRules.exceptionHandler.prepend{ -// case(_, r, e) if tryo(DB.use(DefaultConnectionIdentifier){ conn => conn}.isClosed).getOrElse(true) => { -// logger.error("Exception being returned to browser when processing " + r.uri.toString, e) -// JsonResponse( -// Extraction.decompose(ErrorMessage(code = 500, message = s"${ErrorMessages.DatabaseConnectionClosedError}")), -// 500 -// ) -// } + case(_, r, e) if e.isInstanceOf[NullPointerException] && e.getMessage.contains("Looking for Connection Identifier") => { + logger.error(s"Exception being returned to browser when processing url is ${r.request.uri}, method is ${r.request.method}, exception detail is $e", e) + JsonResponse( + Extraction.decompose(ErrorMessage(code = 500, message = s"${ErrorMessages.DatabaseConnectionClosedError}")), + 500 + ) + } case(Props.RunModes.Development, r, e) => { logger.error(s"Exception being returned to browser when processing url is ${r.request.uri}, method is ${r.request.method}, exception detail is $e", e) JsonResponse( @@ -719,7 +719,7 @@ class Boot extends MdcLoggable { } case (_, r , e) => { sendExceptionEmail(e) - logger.error("Exception being returned to browser when processing " + r.uri.toString, e) + logger.error(s"Exception being returned to browser when processing url is ${r.request.uri}, method is ${r.request.method}, exception detail is $e", e) JsonResponse( Extraction.decompose(ErrorMessage(code = 500, message = s"${ErrorMessages.InternalServerError}")), 500