Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: adjust crash when some error happen in request (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
uziasferreirazup authored Jun 25, 2020
1 parent 41160f5 commit e436ce1
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import br.com.zup.beagle.android.networking.ResponseData
import br.com.zup.beagle.android.view.viewmodel.Response
import org.json.JSONArray
import org.json.JSONObject
import java.lang.Exception
import java.net.URI

internal fun SendRequestInternal.toRequestData(): RequestData = SendRequestActionMapper.toRequestData(this)
Expand Down Expand Up @@ -54,12 +55,19 @@ internal object SendRequestActionMapper {
}

fun toResponse(responseData: ResponseData): Response {
val data = BeagleMoshi.moshi.adapter(Any::class.java).fromJson(String(responseData.data))
return Response(
statusCode = responseData.statusCode,
data = data,
data = getDataFormatted(responseData.data),
headers = responseData.headers,
statusText = responseData.statusText
)
}

private fun getDataFormatted(data: ByteArray): Any? {
return try {
BeagleMoshi.moshi.adapter(Any::class.java).fromJson(String(data))
} catch (e: Exception) {
String(data)
}
}
}

0 comments on commit e436ce1

Please sign in to comment.