Skip to content

Commit

Permalink
Merge pull request #3027 from sasirven/fix/validation-error
Browse files Browse the repository at this point in the history
Fix - Internal Server Error 500 for ValidationError
  • Loading branch information
elegantmoose authored Jul 29, 2024
2 parents 8226359 + 40e2097 commit fc432b6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/api/v2/responses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import json

from aiohttp import web
from json import JSONDecodeError

from aiohttp.web_exceptions import HTTPUnprocessableEntity
from marshmallow.exceptions import ValidationError

from app.api.v2 import errors
Expand Down Expand Up @@ -51,9 +55,9 @@ async def apispec_request_validation_middleware(request, handler):
)
except ValidationError as ex:
# ex: List of objects sent when single object expected
raise JsonHttpBadRequest(
error='Error parsing JSON: Could not validate Schema',
details=str(ex)
formatted_message = json.dumps({"json": ex.messages}, indent=2)
raise HTTPUnprocessableEntity(
text=formatted_message
)
except JSONDecodeError as ex:
raise JsonHttpBadRequest(
Expand Down

0 comments on commit fc432b6

Please sign in to comment.