Skip to content

Commit

Permalink
422 instead of 500 on subject schema error
Browse files Browse the repository at this point in the history
  • Loading branch information
gpkc committed Mar 12, 2024
1 parent cb6aa95 commit 4a0c21c
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, exc_info=True)
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 4a0c21c

Please sign in to comment.