Skip to content
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

Do not allocate empty response in case of error #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

moredure
Copy link
Contributor

@moredure moredure commented Apr 2, 2022

Doc string states that it's return response in case of success or an error in case of error

@coveralls
Copy link

coveralls commented Apr 2, 2022

Coverage Status

Coverage remained the same at 100.0% when pulling 00a3540 on moredure:patch-4 into a09d4b5 on sideshow:master.

client.go Outdated
@@ -185,7 +185,7 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error

decoder := json.NewDecoder(httpRes.Body)
if err := decoder.Decode(&response); err != nil && err != io.EOF {
return &Response{}, err
return nil, err
Copy link
Owner

@sideshow sideshow Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This case is a little different as we've already completed the http request and have headers back etc, but just cant parse the json body, presumably because Apple returned us corrupt json. So in effect the err would be pretty useless to the user as it would be a json decoding err, and the response (even though it only contains a status code and an apns-id may be of more use to them. Semantically, I probably should change it so it returns either a response or an error and not both.

I'm looking to review this error handling in the future to read the error from the GOAWAY frame as it contains useful information.

Copy link
Contributor Author

@moredure moredure Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's very unlikely situation, anyway, I am more concerned about backward compatibility of this change, so it's up to you.

Copy link
Contributor Author

@moredure moredure Apr 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can wrap error with fmt.Errorf("apn: info from header probably or readed response, %w", err) for this case or wrap with custom error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me show you

@moredure moredure force-pushed the patch-4 branch 10 times, most recently from ec1a5c1 to c23618a Compare April 2, 2022 23:10
@moredure moredure requested a review from sideshow April 2, 2022 23:20
Doc string states that it's return response in case of success or an error in case of error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants