From 2efbf0696bc1f59281c4ef4b1b22aea64285f148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 5 Aug 2025 16:02:31 +0200 Subject: [PATCH] feature/Improve error handling at applyAccessTokenRules --- obp-api/src/main/scala/code/api/OAuth2.scala | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/obp-api/src/main/scala/code/api/OAuth2.scala b/obp-api/src/main/scala/code/api/OAuth2.scala index a464be47f..1d0a742e2 100644 --- a/obp-api/src/main/scala/code/api/OAuth2.scala +++ b/obp-api/src/main/scala/code/api/OAuth2.scala @@ -410,10 +410,21 @@ object OAuth2Login extends RestHelper with MdcLoggable { validateAccessToken(token) match { case Full(_) => val user = getOrCreateResourceUser(token) - val consumer = getOrCreateConsumer(token, user.map(_.userId), Some("OAuth 2.0")) - LoginAttempt.userIsLocked(user.map(_.provider).getOrElse(""), user.map(_.name).getOrElse("")) match { - case true => ((Failure(UsernameHasBeenLocked), Some(cc.copy(consumer = consumer)))) - case false => (user, Some(cc.copy(consumer = consumer))) + val consumer: Box[Consumer] = getOrCreateConsumer(token, user.map(_.userId), Some("OAuth 2.0")) + consumer match { + case Full(_) => + LoginAttempt.userIsLocked(user.map(_.provider).getOrElse(""), user.map(_.name).getOrElse("")) match { + case true => ((Failure(UsernameHasBeenLocked), Some(cc.copy(consumer = consumer)))) + case false => (user, Some(cc.copy(consumer = consumer))) + } + case ParamFailure(msg, exception, chain, apiFailure: APIFailure) => + logger.debug(s"ParamFailure - message: $msg, param: $apiFailure, exception: ${exception.map(_.getMessage).openOr("none")}, chain: ${chain.map(_.msg).openOr("none")}") + (ParamFailure(msg, exception, chain, apiFailure: APIFailure), Some(cc)) + case Failure(msg, exception, c) => + logger.error(s"Failure - message: $msg, exception: ${exception.map(_.getMessage).openOr("none")}") + (Failure(msg, exception, c), Some(cc)) + case _ => + (Failure(CreateConsumerError), Some(cc)) } case ParamFailure(a, b, c, apiFailure: APIFailure) => (ParamFailure(a, b, c, apiFailure: APIFailure), Some(cc))