Mike R
07/27/2019, 5:06 PMfun Response<*>.createError(): Error {
val errorBody = this.errorBody() ?: run {
logger.error { "createError failed: null errorBody found" }
throw ClassCastException("Null errorBody found on response")
}
val error = Gson().fromJson(errorBody.string(), models.Error::class.java)
return error
}
What is happening is I am losing the contents of errorBody when I try to use the receiver (Response)... I've read over the docs on class extension and I don't see anything about this?Mark Murphy
07/27/2019, 5:08 PMMike R
07/27/2019, 5:11 PMerrorBody just fine. Once I am in the scope of the extension function, errorBody no longer has the contents (a string)Mark Murphy
07/27/2019, 5:12 PMClassCastException when you call createError()?Mike R
07/27/2019, 5:13 PMerrorBody() it is just an empty stringMike R
07/27/2019, 5:14 PMMark Murphy
07/27/2019, 5:14 PMcreateError() and stepped into errorBody() to see what's happening?Mike R
07/27/2019, 5:15 PMMike R
07/27/2019, 5:15 PMMark Murphy
07/27/2019, 5:16 PMcreateError() function should be able to call errorBody() just fine -- if you are trying to call errorBody() multiple times, though, I don't know if there are any Retrofit-specific limitations that you're running intoMike R
07/27/2019, 5:18 PMerrorBody() fine, it's just that it loses any context that it had before it enters the scope of createError()Mike R
07/27/2019, 5:18 PMMark Murphy
07/27/2019, 5:19 PMerrorBody() call might be consuming the content, such that by the time your second, inside-of-scope errorBody() call is made, the content is gone -- streaming APIs sometimes have destructive read behaviors like thatMike R
07/27/2019, 5:19 PMcreateError()Mike R
07/27/2019, 5:20 PMcreateError()Mike R
07/27/2019, 5:20 PMMark Murphy
07/27/2019, 5:21 PMerrorBody() twice on the same Response, so I'm not sure what the behavior is supposed to beMark Murphy
07/27/2019, 5:22 PMMike R
07/27/2019, 5:22 PMMike R
07/27/2019, 5:22 PMMike R
07/27/2019, 5:22 PMerrorBody() it started working!Mike R
07/27/2019, 5:23 PMMark Murphy
07/27/2019, 5:23 PMiammini5
07/31/2019, 11:08 PM