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

Fix SchemaNotFoundException returns 5xx #1246

Merged
merged 6 commits into from
Aug 3, 2020

Conversation

jewertow
Copy link
Contributor

@jewertow jewertow commented Aug 2, 2020

Background context

#1241

Changes

  • changed return type of SchemaRepository.versions from List<SchemaVersion> to SchemaVersionsResponse

SchemaRepository.versions was returning an empty list in case of failed request. To return 400 status to the client in case of non-existing schema version it was necessary to distinguish between the missing schema version and failed request.
The first option was to throw an exception, but I decided to wrap the result into SchemaVersionsResponse to avoid the overhead of throwing an exception. Additionally it would be necessary to handle this exception in all places that invoke this method.
SchemaVersionsResponse is a wrapper that contains status of request execution and a list of versions (empty list in case of failure).

mareckmareck
mareckmareck previously approved these changes Aug 3, 2020
try {
if (online) {
List<SchemaVersion> v = rawSchemaClient.getVersions(topic.getName());
versionsCache.put(topic, v);
return v;
return SchemaVersionsResponse.succeeded(v);
Copy link
Contributor

Choose a reason for hiding this comment

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

v -> versions? Since in the else branch it is fully named.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


import static java.util.Collections.emptyList;

public class SchemaVersionsResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if Response is the best suited name here. Perhaps Result would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR.getStatusCode());
assertThat(response.getStatus()).isEqualTo(BAD_REQUEST.getStatusCode());
assertThat(response.readEntity(String.class))
.isEqualTo("{\"message\":\"Given schema version does not exist\",\"code\":\"SCHEMA_VERSION_DOES_NOT_EXIST\"}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also return what schema version doesn’t exist in http response? This information will be useful for clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@druminski druminski merged commit 8b3f796 into master Aug 3, 2020
@druminski druminski deleted the 1241-SchemaNotFoundException-returns-5xx branch August 3, 2020 14:59
pwolaq pushed a commit to pwolaq/hermes that referenced this pull request Oct 15, 2020
Return 400 Bad Request in case of non-existing schema version
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.

3 participants