-
Notifications
You must be signed in to change notification settings - Fork 645
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
Google Pub/Sub: Fail source when pull status code is not 200 OK #1928
Conversation
ff2bb0b
to
7d741d6
Compare
pullResponse <- Unmarshal(response).to[PullResponse] | ||
pullResponse <- response.status match { | ||
case StatusCodes.OK => Unmarshal(response).to[PullResponse] | ||
case status => Future.failed(new RuntimeException(s"Unexpected publish response. Code: [${status}]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google PubSub sometimes returns quite nice explanations in body of response.
I was wondering about Unmarshal.to[String]
for non OK responses and adding this information to exception message. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, more error context is always a plus.
7d741d6
to
85d5da2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important improvement!
pullResponse <- Unmarshal(response).to[PullResponse] | ||
pullResponse <- response.status match { | ||
case StatusCodes.OK => Unmarshal(response).to[PullResponse] | ||
case status => Future.failed(new RuntimeException(s"Unexpected publish response. Code: [${status}]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, more error context is always a plus.
Failing ack if response is not success.
.map { entity => | ||
throw new RuntimeException(s"Unexpected pull response. Code: [$status]. Entity: [$entity]") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using same pattern in pull, acknowledge and publish.
I'm matching for every success status code. If it's not successful, then trying to read error as String to add it to an exception. It works for response with no entity, returning empty string (checked in added spec for acknowledge).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thank you! |
Purpose
Changes behavior for pull subscribe stream.
Before: error responses were successfully Unmarshalled to empty PullResponse, giving no signal that errors occurred.
That was because Google PubSub error response bodies are valid JSON messages and PullResponse contains only one optional field.
After: when status code for pull request is not 200 OK, then source will fail with exception that contain no OK response status.
References
References #1902
Background Context
I've used technique similar to current handling of failed publish requests.