Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!