-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response.IsSuccess proposal #169
Comments
@mxpv I understand your recommendation. However, I would like to clarify about resty existing capabilities. Resty has builtin support JSON and XML response handling(automatic unmarshal) for Success and Error scenario based on status code (Like you have described in the recommendation). Let's say, if you have response struct for Success and Error. For example: resp, err := resty.R().
SetHeader(hdrContentTypeKey, jsonContentType).
SetBody(user).
SetResult(AuthSuccess{}).
SetError(AuthError{}).
Post("http://localhost:8080/login")
// Success
if resp.Result() != nil {
result := resp.Result().(*AuthSuccess)
}
// Error
if resp.Error() != nil {
error := resp.Error().(*AuthError)
} Does it satisfy your use case? |
Not really.
So right now I have something like this:
|
Okay, I will add FYI |
@mxpv helper methods added to master branch. Will be released in |
@jeevatkm thanks a lot! |
Hey.
I have an API which returns body in case of success or 4xx/5xx and error status text in case of error.
It would be nice to add
IsSuccess
helper, something like:This is very similar
IsSuccessStatusCode
in https://stackoverflow.com/questions/32569860/checking-if-httpstatuscode-represents-success-or-failureThe implementation is trivial:
What do you think?
Thanks.
The text was updated successfully, but these errors were encountered: