Some part of my app use Google Spreadsheet.
And I implemented REST API there with Apps Script.
I think this is rare case but, google server gives me 200 with html code when it has server error.
So, what I am trying is getting the response with ApiResponse. And then try to convert the response to SpreadSheetResponseBody which is a data class when it's successful.
This is my concept.
suspend fun updateDashboard(
ssId: String,
method: String,
device: String,
isTest: Boolean,
request: KioskDashboardReqBody
): ApiResponse<SpreadSheetResponseBody>{
val result = service.updateDashboard(ssId, method, device, isTest, request).onSuccess {
try {
val data = Gson().fromJson(this.data, SpreadSheetResponseBody::class.java)
return ApiResponse.Success<SpreadSheetResponseBody>(data)
}catch(e: Exception){
return ApiResponse.Failure<SpreadSheetResponseBody>(e)
}
}
return ApiResponse.Failure<SpreadSheetResponseBody>("Server Error")
}
This code is invalid.
Since google gives me 200. I'd like to create ApiResponse instead in the Repository.