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

Google Pub/Sub: Fail source when pull status code is not 200 OK #1928

Merged
merged 2 commits into from
Sep 13, 2019

Conversation

LGLO
Copy link
Contributor

@LGLO LGLO commented Sep 10, 2019

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.

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}]"))
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

@ennru ennru left a 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}]"))
Copy link
Member

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.

@ennru ennru changed the title Failing subscribe source when pull response code is not 200 OK. Google Pub/Sub: Fail source when pull status code is not 200 OK Sep 11, 2019
Failing ack if response is not success.
.map { entity =>
throw new RuntimeException(s"Unexpected pull response. Code: [$status]. Entity: [$entity]")
}
}
Copy link
Contributor Author

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).

Copy link
Member

@ennru ennru left a comment

Choose a reason for hiding this comment

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

LGTM.

@ennru ennru merged commit befcda8 into akka:master Sep 13, 2019
@ennru ennru added this to the 2.0.0 milestone Sep 13, 2019
@ennru
Copy link
Member

ennru commented Sep 13, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants