From 4aa8b3033c8b32694b870a294b5f75f03b866fa6 Mon Sep 17 00:00:00 2001 From: Stefano Russello Date: Fri, 19 Apr 2024 11:03:41 +0200 Subject: [PATCH] SE-861 - CloudMatrixCall failure handling --- build.gradle | 4 ++-- .../streamamg_sdk_cloudmatrix/network/CloudMatrixCall.kt | 6 +++++- .../com/streamamg/streamapi_core/models/StreamAMGError.kt | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 1eb1ded..49daab7 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,8 @@ plugins { id 'maven-publish' } // Versions of the library modules are matched (eg 1.0 core goes with 1.0 cloudmatrix) to prevent dependency issues -ext.SDK_VERSION_CODE = 26 -ext.SDK_VERSION_NAME = "1.2.6" +ext.SDK_VERSION_CODE = 27 +ext.SDK_VERSION_NAME = "1.2.7" publishing { publications { diff --git a/streamamg-sdk-cloudmatrix/src/main/java/com/streamamg/streamamg_sdk_cloudmatrix/network/CloudMatrixCall.kt b/streamamg-sdk-cloudmatrix/src/main/java/com/streamamg/streamamg_sdk_cloudmatrix/network/CloudMatrixCall.kt index 9ca8a48..7a020d6 100644 --- a/streamamg-sdk-cloudmatrix/src/main/java/com/streamamg/streamamg_sdk_cloudmatrix/network/CloudMatrixCall.kt +++ b/streamamg-sdk-cloudmatrix/src/main/java/com/streamamg/streamamg_sdk_cloudmatrix/network/CloudMatrixCall.kt @@ -14,13 +14,17 @@ open class CloudMatrixCall { call.enqueue(object : Callback { override fun onFailure(call: Call, t: Throwable) { logErrorCM("Call to CloudMatrix failed: ${t.localizedMessage}") + + response(StreamAMGError(message = t.message.orEmpty(), throwable = t)) } override fun onResponse(call: Call, response: Response) { if (response.isSuccessful) { val model = response.body() - model?.let { + if(model != null) { response(model) + } else { + response(StreamAMGError(response.code(), response.message().orEmpty())) } } else { response(StreamAMGError(response.code(), response.message())) diff --git a/streamamg-sdk-core/src/main/java/com/streamamg/streamapi_core/models/StreamAMGError.kt b/streamamg-sdk-core/src/main/java/com/streamamg/streamapi_core/models/StreamAMGError.kt index 86e18b0..3acf577 100644 --- a/streamamg-sdk-core/src/main/java/com/streamamg/streamapi_core/models/StreamAMGError.kt +++ b/streamamg-sdk-core/src/main/java/com/streamamg/streamapi_core/models/StreamAMGError.kt @@ -3,7 +3,7 @@ package com.streamamg.streamapi_core.models /** * Model returned when a SDK call is unavailable or reports an error */ -class StreamAMGError(val code: Int = -1, message: String) +class StreamAMGError(val code: Int = -1, message: String, throwable: Throwable? = null) { /** * Returns an error code - generally HTTP - for a failed call