Description
In goodmap/admin_api.py, the _create_location_handler and _update_location_handler functions currently catch Pydantic's ValidationError in the generic Exception handler, which returns a 500 Internal Server Error instead of the more appropriate 400 Bad Request.
Proposed Solution
Add specific except blocks for Pydantic's ValidationError in both handlers:
- Import
ValidationError from pydantic
- Add
except ValidationError as e: block after the existing except LocationValidationError as e block
- Handle validation errors with a 400 response instead of 500
Context
TODO comments have been added to the code as placeholders.
Description
In
goodmap/admin_api.py, the_create_location_handlerand_update_location_handlerfunctions currently catch Pydantic'sValidationErrorin the genericExceptionhandler, which returns a 500 Internal Server Error instead of the more appropriate 400 Bad Request.Proposed Solution
Add specific except blocks for Pydantic's
ValidationErrorin both handlers:ValidationErrorfrompydanticexcept ValidationError as e:block after the existingexcept LocationValidationError as eblockContext
TODO comments have been added to the code as placeholders.