Skip to content

Commit

Permalink
api(views): improve error handling security (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
caio-felipee authored Dec 21, 2023
1 parent 3455261 commit 303c0c8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api/api/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from api.models import Discipline
from api.views.utils import handle_400_error

from traceback import print_exception

MAXIMUM_RETURNED_DISCIPLINES = 15
ERROR_MESSAGE = "no valid argument found for 'search', 'year' or 'period'"
Expand Down Expand Up @@ -224,9 +225,17 @@ def post(self, request: request.Request, *args, **kwargs) -> response.Response:
schedules = schedule_generator.generate()
except Exception as error:
"""Retorna um erro caso ocorra algum erro ao criar o gerador de horários"""

message_error = "An internal error has occurred."

if type(error) is ValueError:
message_error = str(error)
else: # pragma: no cover
print_exception(error)

return response.Response(
{
"errors": str(error)
"errors": message_error
}, status.HTTP_400_BAD_REQUEST)

data = []
Expand Down

0 comments on commit 303c0c8

Please sign in to comment.