From 88c276bb34d4811fb795cbcc70d3dd5ea81446d9 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 18 Sep 2024 14:22:37 +0530 Subject: [PATCH] handling exceptions in authorizeSession API Signed-off-by: Gaurav Goel --- .../session_manager_android/SessionManager.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt index 3df1e67..9beb408 100644 --- a/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt +++ b/session-manager-android/src/main/java/com/web3auth/session_manager_android/SessionManager.kt @@ -94,8 +94,15 @@ class SessionManager(context: Context, sessionTime: Int = 86400, allowedOrigin: } } + if (!(response.isSuccessful)) { + throw Exception( + SessionManagerError.getError( + ErrorCode.SOMETHING_WENT_WRONG + ) + ) + } - if (!(response.isSuccessful && response.body() != null && response.body()?.message != "")) { + if (response.body()?.success == false && response.body()?.message.isNullOrEmpty()) { throw Exception( SessionManagerError.getError( ErrorCode.NOUSERFOUND @@ -106,6 +113,14 @@ class SessionManager(context: Context, sessionTime: Int = 86400, allowedOrigin: val messageObj = response.body()?.message?.let { JSONObject(it).toString() } + if (messageObj.isNullOrEmpty()) { + throw Exception( + SessionManagerError.getError( + ErrorCode.NOUSERFOUND + ) + ) + } + val ecies: Ecies = gson.fromJson( messageObj, Ecies::class.java )