Skip to content

Commit

Permalink
IJMP-1096: move possible response messages to map
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzianis Lisiankou committed Feb 2, 2024
1 parent 222cc95 commit 74fe5e8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import eu.ibagroup.formainframe.utils.castOrNull
import eu.ibagroup.formainframe.utils.gson
import retrofit2.Response

/** The map contains the correspondence between the response message and the message for the user. */
val responseMessageMap = mapOf(
Pair("Unauthorized", "Credentials are not valid"),
Pair("Not Found", "Endpoint not found")
)

/**
* Generating an exception message string.
* @param code exception code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.ibagroup.formainframe.dataops.RemoteQuery
import eu.ibagroup.formainframe.dataops.attributes.JobsRequester
import eu.ibagroup.formainframe.dataops.attributes.RemoteJobAttributes
import eu.ibagroup.formainframe.dataops.exceptions.CallException
import eu.ibagroup.formainframe.dataops.exceptions.responseMessageMap
import eu.ibagroup.formainframe.utils.asMutableList
import eu.ibagroup.formainframe.utils.cancelByIndicator
import eu.ibagroup.formainframe.utils.log
Expand Down Expand Up @@ -119,7 +120,8 @@ class JobFetchProvider(dataOpsManager: DataOpsManager) :
log.info("No jobs returned for query $query. Skipping")
}
} else {
exception = CallException(response, "Cannot retrieve Job files list")
val headMessage = responseMessageMap[response.message()] ?: "Cannot retrieve Job files list"
exception = CallException(response, headMessage)
}

if (exception != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.ibagroup.formainframe.dataops.RemoteQuery
import eu.ibagroup.formainframe.dataops.UnitRemoteQueryImpl
import eu.ibagroup.formainframe.dataops.attributes.FileAttributes
import eu.ibagroup.formainframe.dataops.exceptions.CallException
import eu.ibagroup.formainframe.dataops.exceptions.responseMessageMap
import eu.ibagroup.formainframe.utils.castOrNull

/**
Expand Down Expand Up @@ -99,7 +100,8 @@ abstract class RemoteBatchedFileFetchProviderBase<ResponseList : Any, ResponseIt
val attributes = fetchedItems?.map { buildAttributes(query, it) }

if (failedResponse != null) {
throw CallException(failedResponse, "Cannot retrieve dataset list")
val headMessage = responseMessageMap[failedResponse.message()] ?: "Cannot retrieve dataset list"
throw CallException(failedResponse, headMessage)
}

return attributes ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ abstract class RemoteFileFetchProviderBase<Connection : ConnectionConfigBase, Re
cleanCacheInternal(query, false)
sendTopic(FileFetchProvider.CACHE_CHANGES, dataOpsManager.componentManager).onFetchCancelled(query)
} else {
var errorMessage = throwable.message ?: "Error"
errorMessage = errorMessage.replace("\n", " ")
if (throwable is CallException) {
val details = throwable.errorParams?.get("details")
var errorMessage = throwable.message ?: "Error"
if (details is List<*>) {
errorMessage = details[0] as String
}
errorMessages[query] =
service<ErrorSeparatorService>().separateErrorMessage(errorMessage)["error.description"] as String
} else {
val errorMessage = throwable.message ?: "Error"
errorMessages[query] = errorMessage
}
cache[query] = listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.ibagroup.formainframe.dataops.RemoteQuery
import eu.ibagroup.formainframe.dataops.attributes.RemoteJobAttributes
import eu.ibagroup.formainframe.dataops.attributes.RemoteSpoolFileAttributes
import eu.ibagroup.formainframe.dataops.exceptions.CallException
import eu.ibagroup.formainframe.dataops.exceptions.responseMessageMap
import eu.ibagroup.formainframe.dataops.getAttributesService
import eu.ibagroup.formainframe.utils.cancelByIndicator
import eu.ibagroup.formainframe.utils.log
Expand Down Expand Up @@ -89,7 +90,8 @@ class SpoolFileFetchProvider(dataOpsManager: DataOpsManager) :
attributes?.joinToString("\n") ?: ""
}
} else {
exception = CallException(response, "Cannot retrieve Job files list")
val headMessage = responseMessageMap[response.message()] ?: "Cannot retrieve Job files list"
exception = CallException(response, headMessage)
}

if (exception != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import eu.ibagroup.formainframe.dataops.DataOpsManager
import eu.ibagroup.formainframe.dataops.RemoteQuery
import eu.ibagroup.formainframe.dataops.attributes.RemoteUssAttributes
import eu.ibagroup.formainframe.dataops.exceptions.CallException
import eu.ibagroup.formainframe.dataops.exceptions.responseMessageMap
import eu.ibagroup.formainframe.utils.cancelByIndicator
import eu.ibagroup.formainframe.utils.log
import eu.ibagroup.formainframe.vfs.MFVirtualFile
Expand Down Expand Up @@ -91,7 +92,8 @@ class UssFileFetchProvider(
attributes?.joinToString("\n") ?: ""
}
} else {
exception = CallException(response, "Cannot retrieve USS files list")
val headMessage = responseMessageMap[response.message()] ?: "Cannot retrieve USS files list"
exception = CallException(response, headMessage)
}

if (exception != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import eu.ibagroup.formainframe.api.api
import eu.ibagroup.formainframe.config.connect.authToken
import eu.ibagroup.formainframe.dataops.DataOpsManager
import eu.ibagroup.formainframe.dataops.exceptions.CallException
import eu.ibagroup.formainframe.dataops.exceptions.responseMessageMap
import eu.ibagroup.formainframe.utils.cancelByIndicator
import eu.ibagroup.formainframe.utils.log
import org.zowe.kotlinsdk.SystemsApi
Expand Down Expand Up @@ -56,11 +57,7 @@ class InfoOperationRunner : OperationRunner<InfoOperation, SystemsResponse> {
.cancelByIndicator(progressIndicator)
.execute()
if (!response.isSuccessful) {
val headMessage = when (response.message()) {
"Unauthorized" -> "Credentials are not valid"
"Not Found" -> "Endpoint not found"
else -> response.message()
}
val headMessage = responseMessageMap[response.message()] ?: response.message()
throw CallException(response, headMessage)
}
return response.body() ?: throw CallException(response, "Cannot parse z/OSMF info request body")
Expand Down

0 comments on commit 74fe5e8

Please sign in to comment.