Often (especially when debugging) a server will respond with detailed error messages (often including stack traces, etc.) when serving a 400 or 500; when using validate(200..<300) (or similar) all that Alamofire gives in the error is, e.g. ResponseValidationFailureReason.unacceptableStatusCode(400).
It would be nice to see the server response body in this error type as well.
Right now the best way to accomplish that is to put such error handling inside your response serializer. That way you can share code between your normal response handling and the special error handling. We're hoping to revisit the validate vs. response functions in the future, but for now this should work.
Any update on this? I've just started using Moya and got bitten by this.
same here. I am also gettting 400 status code ..not not getting the reason why this is coming. I tried a,, the option for eating.
+1
Attaching the response body to the error is unlikely to happen, as the data could very large, even if we refactor the validate vs. response handling. I suggest you look into customizing your response serializer.
@jshier I'm not sure I understand, what sort of problems would a very large response body create in the case of e.g. a 500?
(Also, I have never encountered an API which returns very large bodies for errors. Is that common enough that it should justify design decisions which affect all users of Alamofire?)
This error is used for any response code outside the valid range, which could be customized in ways we can't anticipate, including use in a backend system that includes large responses, intentionally or not. There is no single standard practice here so we must be conservative when offering default behaviors.
Like I said, customizing the response handler is appropriate place to put this logic for now.
Could you provide an example of that?
Our response handling is well documented, even for custom cases.
Do you have any specific examples of customizing the response handler to pass along the error response body? The two examples you cited, unless I'm missing something (which is entirely possible) don't make any mention of passing along the response body and instead seem quite similar to the existing default jsonResponseSerialiazer. I've seen so many folks ask about this functionality, but have yet to see a concrete example. It would be enormously helpful.
Most helpful comment
Do you have any specific examples of customizing the response handler to pass along the error response body? The two examples you cited, unless I'm missing something (which is entirely possible) don't make any mention of passing along the response body and instead seem quite similar to the existing default
jsonResponseSerialiazer.I've seen so many folks ask about this functionality, but have yet to see a concrete example. It would be enormously helpful.