Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
BOOL_ERROR_MESSAGE = "ValueError: boolean values expected [True,False,1,0]. rage_inducing | action_packed | skill_based | mature_themes | open_world | multiplayer"

def raise_request_error(message):
"""Raises HTTPError with code 422 for bad input with a custom message."""
raise HTTPException(status_code=422, detail=message)
"""Raises HTTPError with code 400 for bad input with a custom message."""
raise HTTPException(status_code=400, detail=message)

def raise_boolean_error():
"""Raises HTTPError with code 422 for when input values aren't booleans."""
raise HTTPException(status_code=422, detail=BOOL_ERROR_MESSAGE)
"""Raises HTTPError with code 400 for when input values aren't booleans."""
raise HTTPException(status_code=400, detail=BOOL_ERROR_MESSAGE)
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from app import input_parser as parser
from app.database import get_db

VERSION = "1.1.1"
VERSION = "1.1.2"
# Prometheus metrics
REQUEST_COUNT = Counter("http_requests_total", "Total HTTP requests", ["method", "endpoint", "status"])
REQUEST_LATENCY = Summary("http_request_latency_seconds", "Request latency in seconds")
Expand Down
4 changes: 2 additions & 2 deletions test/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class TestRequestErrorHandling(unittest.TestCase):
def test_request_error_handling(self):
with self.assertRaises(HTTPException) as _:
error.raise_request_error("")
self.assertEqual(_.exception.status_code,422,msg = "Wrong status code was given")
self.assertEqual(_.exception.status_code,400,msg = "Wrong status code was given")

class TestBooleanErrorHandling(unittest.TestCase):
def test_boolean_error_handling(self):
with self.assertRaises(HTTPException) as _:
error.raise_boolean_error()
self.assertEqual(_.exception.status_code,422,msg = "Wrong status code was given")
self.assertEqual(_.exception.status_code,400,msg = "Wrong status code was given")
2 changes: 1 addition & 1 deletion test/test_input_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ def test_parse_input(self):
def test_wrong_input(self):
with self.assertRaises(HTTPException) as _:
TestClass = parser.parse_input([1,"a",False,{"Name":"Test"}])
self.assertEqual(_.exception.status_code,422,msg = "Incorrect or no error raised with wrong datatypes")
self.assertEqual(_.exception.status_code,400,msg = "Incorrect or no error raised with wrong datatypes")