Skip to content

Commit

Permalink
handling exceptions in authorizeSession API
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
grvgoel81 authored and Gaurav Goel committed Sep 18, 2024
1 parent c77fde3 commit 88c276b
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit 88c276b

Please sign in to comment.