Skip to content

Commit

Permalink
Merge pull request #837 from gpkc/subject-invalid-schema
Browse files Browse the repository at this point in the history
422 instead of 500 on subject schema error
  • Loading branch information
aiven-anton authored Mar 13, 2024
2 parents cb6aa95 + 82a7c44 commit 143fa73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions karapace/schema_registry_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,14 +1104,14 @@ async def subjects_schema_post(
schema_type=schema_type, schema_str=schema_str, references=references, dependencies=new_schema_dependencies
)
except InvalidSchema:
self.log.exception("No proper parser found")
self.log.warning("Invalid schema: %r", schema_str)
self.r(
body={
"error_code": SchemaErrorCodes.HTTP_INTERNAL_SERVER_ERROR.value,
"error_code": SchemaErrorCodes.INVALID_SCHEMA.value,
"message": f"Error while looking up schema under subject {subject}",
},
content_type=content_type,
status=HTTPStatus.INTERNAL_SERVER_ERROR,
status=HTTPStatus.UNPROCESSABLE_ENTITY,
)
except InvalidReferences:
human_error = "Provided references is not valid"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ async def test_schema_subject_post_invalid(registry_async_client: Client) -> Non
f"subjects/{subject_1}",
json={"schema": json.dumps({"type": "invalid_type"})},
)
assert res.status_code == 500, "Invalid schema for existing subject should return 500"
assert res.status_code == 422, "Invalid schema for existing subject should return 422"
assert res.json()["message"] == f"Error while looking up schema under subject {subject_1}"

# Subject is not found
Expand Down

0 comments on commit 143fa73

Please sign in to comment.