Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added causes to error handling where possible. #76

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONArray
import org.json.JSONObject
import retrofit2.HttpException
import java.io.ByteArrayOutputStream
import java.io.File

Expand Down Expand Up @@ -130,8 +131,8 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
outputStream
} else {
if (mimeType == null) {
val errorBody = response.errorBody()?.string().orEmpty()
throw (OmhStorageException.DownloadException(DOWNLOAD_ERROR, errorBody))
val cause = HttpException(response)
throw (OmhStorageException.DownloadException(DOWNLOAD_ERROR, cause))
}

return exportDocEditor(fileId, mimeType)
Expand All @@ -149,8 +150,8 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
return if (response.isSuccessful) {
outputStream
} else {
val errorBody = response.errorBody()?.string().orEmpty()
throw (OmhStorageException.DownloadException(DOWNLOAD_GOOGLE_WORKSPACE_ERROR, errorBody))
val cause = HttpException(response)
throw (OmhStorageException.DownloadException(DOWNLOAD_GOOGLE_WORKSPACE_ERROR, cause))
}
}
override fun updateFile(
Expand All @@ -171,8 +172,7 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
val omhFile = response.body()?.toFile() ?: return null
updateMediaFile(localFileToUpload, omhFile)
} else {
val errorBody = response.errorBody()?.string().orEmpty()
throw OmhStorageException.UpdateException(UPDATE_META_DATA, errorBody)
throw OmhStorageException.UpdateException(UPDATE_META_DATA, HttpException(response))
}
}

Expand All @@ -191,8 +191,7 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
return if (response.isSuccessful) {
response.body()?.toFile()
} else {
val errorBody = response.errorBody()?.string().orEmpty()
throw OmhStorageException.UpdateException(UPDATE_CONTENT_FILE, errorBody)
throw OmhStorageException.UpdateException(UPDATE_CONTENT_FILE, HttpException(response))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OmhStorageProvider private constructor(
val storageFactory: OmhStorageFactory = try {
getOmhStorageFactory(context)
} catch (exception: ClassNotFoundException) {
throw OmhStorageException.ApiException(OmhAuthStatusCodes.DEVELOPER_ERROR)
throw OmhStorageException.ApiException(OmhAuthStatusCodes.DEVELOPER_ERROR, exception)
}

return storageFactory.getStorageClient(authClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package com.omh.android.storage.api.domain.model

import com.omh.android.auth.api.models.OmhAuthStatusCodes

sealed class OmhStorageException(val statusCode: Int) : Exception() {
sealed class OmhStorageException(private val statusCode: Int) : Exception() {

override val message: String?
get() = OmhAuthStatusCodes.getStatusCodeString(statusCode)

class InvalidCredentialsException(statusCode: Int) : OmhStorageException(statusCode)

class ApiException(statusCode: Int) : OmhStorageException(statusCode)
class ApiException(statusCode: Int, override val cause: Throwable? = null) : OmhStorageException(statusCode)

class DownloadException(
statusCode: Int,
override val message: String
override val cause: Throwable?
) : OmhStorageException(statusCode)

class UpdateException(
statusCode: Int,
override val message: String
override val cause: Throwable?
) : OmhStorageException(statusCode)
}