Skip to content

Commit

Permalink
fix flask
Browse files Browse the repository at this point in the history
  • Loading branch information
llbonet14 committed Feb 2, 2024
1 parent 81cdd20 commit 69cdce9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
app = Flask(__name__)

# This must be imported after the Flask app is created
from service import routes # pylint: disable=wrong-import-position,cyclic-import
from service.common import log_handlers # pylint: disable=wrong-import-position
from service import routes
from service.common import log_handlers

log_handlers.init_logging(app, "gunicorn.error")

Expand Down
10 changes: 6 additions & 4 deletions service/common/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def bad_request(error):
app.logger.warning(message)
return (
jsonify(
status=status.HTTP_400_BAD_REQUEST, error="Bad Request",
status=status.HTTP_400_BAD_REQUEST,
error="Bad Request",
message=message
),
status.HTTP_400_BAD_REQUEST,
Expand All @@ -45,9 +46,10 @@ def not_found(error):
message = str(error)
app.logger.warning(message)
return (
jsonify(status=status.HTTP_404_NOT_FOUND, error="Not Found",
message=message),
status.HTTP_404_NOT_FOUND,
jsonify(
status=status.HTTP_404_NOT_FOUND,
error="Not Found",
message=message), status.HTTP_404_NOT_FOUND,
)


Expand Down
10 changes: 6 additions & 4 deletions service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def list_counters():
"""Lists all counters"""
app.logger.info("Request to list all counters...")

counters = [dict(name=count[0], counter=count[1]) for count in COUNTER.items()]
counters = [dict(name=count[0], counter=count[1])
for count in COUNTER.items()]

return jsonify(counters)

Expand All @@ -54,7 +55,8 @@ def create_counters(name):
app.logger.info("Request to Create counter: %s...", name)

if name in COUNTER:
return abort(status.HTTP_409_CONFLICT, f"Counter {name} already exists")
return abort(status.HTTP_409_CONFLICT,
f"Counter {name} already exists")

COUNTER[name] = 0

Expand All @@ -75,7 +77,7 @@ def read_counters(name):
app.logger.info("Request to Read counter: %s...", name)

if name not in COUNTER:
return abort(status.HTTP_404_NOT_FOUND,
return abort(status.HTTP_404_NOT_FOUND,
f"Counter {name} does not exist")

counter = COUNTER[name]
Expand All @@ -91,7 +93,7 @@ def update_counters(name):
app.logger.info("Request to Update counter: %s...", name)

if name not in COUNTER:
return abort(status.HTTP_404_NOT_FOUND,
return abort(status.HTTP_404_NOT_FOUND,
f"Counter {name} does not exist")

COUNTER[name] += 1
Expand Down

0 comments on commit 69cdce9

Please sign in to comment.