question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not nullable body on success

See original GitHub issue

In ApiResponse.Success the data property is nullable. And i understand why it is - it’s just a wrapper around retrofit response logic. But, when i’m using clean suspend fun something(): Type i will get an exception if the returned type is null. Which is good, i do expect that!

If i wanted null to be possible in my response - i would use a nullable type as a generic parameter. If i don’t - my assumption is that in case of success it will always be properly created. The need for another null check does make the whole Success type pointless in my opinion. Because i’m still not sure if it really was a success, i have to do another check…

Have you considered handling that?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jakosscommented, May 24, 2021

From my perspective 204 should be always by design. So when i want to handle 204 i just don’t require any response type (in Sandwich that could be represented by a Unit type maybe? (I’m not 100% sure about that, but maybe Sandwich could allow 204 as a success only if return type is Unit? Is that even possible in kotlin, not sure here 😃 ).

Or maybe different response handling type, something like NoContentApiResponse instead of ApiResponse. That seems to me like fine explicit solution to that. That way programmer always have to explicitly declare that they do not expect body.

0reactions
skydovescommented, Jun 25, 2021

Released a new stable 1.2.0. 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Status Code to use for Successful but null body?
My team and myself are trying to decide on what Status Code to use, our API Client Generated via Swagger has a condition...
Read more >
Possibility to send NULL in POST request. · Issue #109 - GitHub
Hey there, I'm using RestEase Version="1.4.7" for net core application. I faced with interesting issue. I have a simple interface: public ...
Read more >
Postman PUT returns success, but parameters are null in ...
Why the actual response contains "null" values though the status is success. I have added content-type as application/json in the request header ...
Read more >
Understanding null safety - Dart
Dart needs to ensure a non-nullable local variable is always initialized before it is read. We use definite assignment analysis to be as...
Read more >
Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found