Improve 204 (No content) handling and polymorphism #79
-
DescriptionThere has been a PR (#63) that introduces the capability of returning ApiResult<Unit, ...> when a 204 occurs. This is generally fine if we expect that that is the only successful behavior. But what if an endpoint can return a 200 with a specific body response, but can also return a 204 with no body? I'd like to open discussion and maybe ask for some guidance regarding this. I've also seen the README which kind of talks about 200 polymorphism but it again seems to only relate with errors. There's a few options to resolve this:
Is there any other option? Thank you. Requirements (place an
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Retrofit handles this by just coercing to |
Beta Was this translation helpful? Give feedback.
-
I'm going to close this discussion and suggest if anyone has this same problem to follow the Optional approach suggested above 👍 |
Beta Was this translation helpful? Give feedback.
-
I'm reopening this as using The only options I see are either intercepting these 204/205 requests and forcing some other response, or hammering some logic on ApiResultCallAdapter to support Optional there which doesn't make any sense. If I end up finding an acceptable workaround I'll post here. |
Beta Was this translation helpful? Give feedback.
I'd say at this point it is mostly a limitation of Retrofit, I just left this as other people could find themselves in the same situation. I'll leave the solution that works ok below with an expected return of
ApiResult<Optional<T>, Throwable>
and a specific annotation@OptionalNoContent
, although I don't really like it.