Skip to content

Commit

Permalink
chore: Applied suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Seluj78 committed Sep 20, 2024
1 parent 47ea2f5 commit bfd2b56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ early_access: true
reviews:
profile: assertive
request_changes_workflow: true
collapse_walkthrough: true
collapse_walkthrough: false
10 changes: 7 additions & 3 deletions flask_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def _handle_bad_request(
raise BadRequestError(message, solution) from original_exception
else:
error_response = {"error": message}
if solution:
error_response["solution"] = solution
return make_response(jsonify(error_response), status_code)


Expand Down Expand Up @@ -287,19 +289,21 @@ def wrapper(*args, **kwargs): # type: ignore
for key, type_hint in parameters.items():
if not _is_optional(type_hint) and key not in data:
return _handle_bad_request(
use_error_handlers, f"Missing key: {key}", f"Expected keys are: {parameters.keys()}"
use_error_handlers, f"Missing key: {key}", f"Expected keys are: {list(parameters.keys())}"
)

for key in data:
if key not in parameters:
return _handle_bad_request(
use_error_handlers, f"Unexpected key: {key}.", f"Expected keys are: {parameters.keys()}"
use_error_handlers, f"Unexpected key: {key}.", f"Expected keys are: {list(parameters.keys())}"
)

for key in data:
if key in parameters and not _check_type(data[key], parameters[key], allow_empty):
return _handle_bad_request(
use_error_handlers, f"Wrong type for key {key}.", f"It should be {parameters[key]}"
use_error_handlers,
f"Wrong type for key {key}.",
f"It should be {getattr(parameters[key], '__name__', str(parameters[key]))}",
)

return fn(*args, **kwargs)
Expand Down

0 comments on commit bfd2b56

Please sign in to comment.