@@ -20,17 +20,29 @@ class CustomObjectId(ObjectId):
2020 purpose of handling MongoDB `_id` fields that are of type `ObjectId`.
2121 """
2222
23- def __init__ (self , value : str , entity_type : Optional [str ] = None , not_found_if_invalid : bool = False ):
23+ def __init__ (
24+ self ,
25+ value : str ,
26+ entity_type : Optional [str ] = None ,
27+ not_found_if_invalid : bool = False ,
28+ response_detail : Optional [str ] = None ,
29+ ):
2430 """
2531 Construct a `CustomObjectId` from a string.
2632
2733 :param value: The string value to be validated, representing the `ObjectId`.
2834 :param entity_type: Name of the entity type e.g. catalogue categories/systems (Used for logging).
2935 :param not_found_if_invalid: Whether an error due to an invalid ID should be raised as a not found error
30- or not. Unprocessable entity is used if left as the default value False.
36+ or not. Unprocessable entity is used if left as the default value False.
37+ :param response_detail: Response detail to return in the the request if uncaught, overrides any error message
38+ constructed by the other parameters.
3139 :raises InvalidObjectIdError: If the string value is an invalid `ObjectId`.
3240 """
33- response_detail = None if entity_type is None else f"{ entity_type .capitalize ()} not found"
41+ response_detail = (
42+ response_detail
43+ if response_detail is not None
44+ else (None if entity_type is None else f"{ entity_type .capitalize ()} not found" )
45+ )
3446 status_code = status .HTTP_404_NOT_FOUND if not_found_if_invalid else None
3547
3648 if not isinstance (value , str ):
0 commit comments