Skip to content

Commit

Permalink
Storage sdk: throw error.
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-hamel committed Jul 3, 2023
1 parent a20c178 commit 8e36773
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.omh.android.storage.api.domain.model.OmhFile
import com.omh.android.storage.api.domain.model.OmhStorageException
import com.omh.android.storage.api.domain.model.OmhStorageStatusCodes.DOWNLOAD_ERROR
import com.omh.android.storage.api.domain.model.OmhStorageStatusCodes.DOWNLOAD_GOOGLE_WORKSPACE_ERROR
import com.omh.android.storage.api.domain.model.OmhStorageStatusCodes.UPDATE_CONTENT_FILE
import com.omh.android.storage.api.domain.model.OmhStorageStatusCodes.UPDATE_META_DATA
import com.omh.android.storage.api.drive.nongms.data.GoogleRetrofitImpl
import com.omh.android.storage.api.drive.nongms.data.GoogleStorageApiService
import com.omh.android.storage.api.drive.nongms.data.source.body.CreateFileRequestBody
Expand Down Expand Up @@ -159,7 +161,6 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
val jsonMetaData = JSONObject().apply {
put(FILE_NAME_KEY, localFileToUpload.name)
put(FILE_PARENTS_KEY, parentId.isNullOrBlank())
put("description", "TEST HANS VIII")
}

val jsonRequestBody = jsonMetaData.toString().toRequestBody(JSON_MIME_TYPE)
Expand All @@ -172,7 +173,8 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
val omhFile = response.body()?.toFile()
updateMediaFile(localFileToUpload, omhFile)
} else {
null
val errorBody = response.errorBody()?.string().orEmpty()
throw (OmhStorageException.DownloadException(UPDATE_META_DATA, errorBody))
}
}

Expand All @@ -195,7 +197,8 @@ internal class NonGmsFileRemoteDataSourceImpl(private val retrofitImpl: GoogleRe
return if (response.isSuccessful) {
response.body()?.toFile()
} else {
null
val errorBody = response.errorBody()?.string().orEmpty()
throw (OmhStorageException.DownloadException(UPDATE_CONTENT_FILE, errorBody))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ object OmhStorageStatusCodes {

const val DOWNLOAD_ERROR = 1
const val DOWNLOAD_GOOGLE_WORKSPACE_ERROR = 2
const val UPDATE_META_DATA = 3
const val UPDATE_CONTENT_FILE = 4

@JvmStatic
fun getStatusCodeString(code: Int): String {
return when (code) {
DOWNLOAD_ERROR -> "Download error."
DOWNLOAD_GOOGLE_WORKSPACE_ERROR -> "Download Google Workspace error."
UPDATE_META_DATA -> "Update meta data error."
UPDATE_CONTENT_FILE -> "Update content file error."
else -> "Unknown status code: $code"
}
}
Expand Down

0 comments on commit 8e36773

Please sign in to comment.