refit: [BUG] Empty Response 202
Describe the bug
Returning accept from ApiGateway. Before I had method similar to this
Task<ApiResponse<object>> CreateMobileUserAccount(CreateUserRequest createUserRequest);
upgrade to latest refit and now I am getting Refit.ApiException : An error occured deserializing the response. ---- System.Text.Json.JsonException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0. -------- System.Text.Json.JsonReaderException : The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (6 by maintainers)
@clairernovotny Quick question on the last part here, as I just ran into the issue with an API that is returning a 204, but by the virtue of it being a 204 response wouldn’t the right thing for Refit to do be to return null or default as 204 means that there is no content and that there shouldn’t be anything to try and deserialize?
@clairernovotny
thanks. I think it is a issue with System.Text.Json. I am use the alternative package and it is working.
@ekjuanrejon My only concern with that option is that it then doesn’t make use of the Serializer that is configured for Refit and you would have to have a separate configuration. The other option of a try/catch just feels dirty, especially when looking for a JsonException specifically vs an ApiException.
@clairernovotny
I was using ApiResponse<object> because I did not know I could use HttpResponseMessage
I will try with HttpResponseMessage.
@bennor I am writing integration tests and I want to assert of the HttpStatusCode returned
Alternatively, if you don’t need to know the exact status code of the response, you could just return
Taskfrom your method:Note that this will also throw on an error status code, which may or may not be what you want.
Re-opening as with the response type of
ApiResponse, you’re right, it shouldn’t be deserializing anything.