-
Notifications
You must be signed in to change notification settings - Fork 218
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
Conversation
try { | ||
if (online) { | ||
List<SchemaVersion> v = rawSchemaClient.getVersions(topic.getName()); | ||
versionsCache.put(topic, v); | ||
return v; | ||
return SchemaVersionsResponse.succeeded(v); |
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.
v -> versions? Since in the else branch it is fully named.
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.
Done
|
||
import static java.util.Collections.emptyList; | ||
|
||
public class SchemaVersionsResponse { |
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.
Not sure if Response
is the best suited name here. Perhaps Result
would be better?
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.
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\"}"); |
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.
Can we also return what schema version doesn’t exist in http response? This information will be useful for clients.
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.
Done
Return 400 Bad Request in case of non-existing schema version
Background context
#1241
Changes
SchemaRepository.versions
fromList<SchemaVersion>
toSchemaVersionsResponse
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).