Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Handle empty body response from service

Im trying to call a service via POST that sends an e-mail to the user, the body always return empty, I have to deal with the response code. e.g. 204 = success.

Im trying to deal this way, but im not succeeding

Service:

@POST("xxxxxx")
fun resendBankSlip(@Path("userId") userId: Int): Deferred<Response>

ViewModel:

scope.launch {
        try {
            _loading.value = true
            val response = repository.sendEmail(userId)
            if (!response.isSuccessful) {
                _error.value = R.string.generic_error_message
            }
        } catch (e: Throwable) {
            _error.value = R.string.generic_error_message
        } finally {
            _loading.value = false
        }
    }

The error happens on val response = repository.sendEmail(userId)

Exception:

java.lang.IllegalArgumentException: 'okhttp3.Response' is not a valid response body type. Did you mean ResponseBody?
for method EmailService.sendEmail

Any idea?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You probably confused okhttp3.Response with retrofit.Response. Try to use retrofit2.Response wrapper in API response like that:

@POST("xxxxxx")
fun resendBankSlip(@Path("userId") userId: Int): Deferred<retrofit2.Response<Unit>>

After that you can easily get response code via response.code().

Also note that I passed Unit as Response's type argument because you don't need the body. In other cases you should pass an actual type of response body.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda