diff --git a/open_city_profile/consts.py b/open_city_profile/consts.py index ff535cf3..89ed4411 100644 --- a/open_city_profile/consts.py +++ b/open_city_profile/consts.py @@ -23,6 +23,7 @@ PROFILE_ALREADY_EXISTS_FOR_USER_ERROR = "PROFILE_ALREADY_EXISTS_FOR_USER_ERROR" PROFILE_MUST_HAVE_PRIMARY_EMAIL = "PROFILE_MUST_HAVE_PRIMARY_EMAIL" INSUFFICIENT_LOA_ERROR = "INSUFFICIENT_LOA_ERROR" +FIELD_NOT_ALLOWED_ERROR = "FIELD_NOT_ALLOWED_ERROR" # Service specific GDPR errors SERVICE_GDPR_API_REQUEST_ERROR = "SERVICE_GDPR_API_REQUEST_ERROR" diff --git a/open_city_profile/exceptions.py b/open_city_profile/exceptions.py index 766209d9..420e70ca 100644 --- a/open_city_profile/exceptions.py +++ b/open_city_profile/exceptions.py @@ -73,3 +73,17 @@ class TokenExchangeError(Exception): class InsufficientLoaError(ProfileGraphQLError): """The requester has insufficient level of authentication to retrieve this data""" + + +class FieldNotAllowedError(ProfileGraphQLError): + """The field is not allowed for the service. + + Field does not exist in the service's allowed data fields (Service.allowed_data_fields). + """ + + field_name: str = None + + def __init__(self, *args, field_name=None, **kwargs): + super().__init__(*args, **kwargs) + + self.field_name = field_name diff --git a/open_city_profile/views.py b/open_city_profile/views.py index e68398d4..d9682cfa 100644 --- a/open_city_profile/views.py +++ b/open_city_profile/views.py @@ -13,6 +13,7 @@ CONNECTED_SERVICE_DELETION_FAILED_ERROR, CONNECTED_SERVICE_DELETION_NOT_ALLOWED_ERROR, DATA_CONFLICT_ERROR, + FIELD_NOT_ALLOWED_ERROR, GENERAL_ERROR, INSUFFICIENT_LOA_ERROR, INVALID_EMAIL_FORMAT_ERROR, @@ -35,6 +36,7 @@ ConnectedServiceDeletionFailedError, ConnectedServiceDeletionNotAllowedError, DataConflictError, + FieldNotAllowedError, InsufficientLoaError, InvalidEmailFormatError, MissingGDPRApiTokenError, @@ -75,6 +77,7 @@ ServiceConnectionDoesNotExist: SERVICE_CONNECTION_DOES_NOT_EXIST_ERROR, ServiceNotIdentifiedError: SERVICE_NOT_IDENTIFIED_ERROR, InsufficientLoaError: INSUFFICIENT_LOA_ERROR, + FieldNotAllowedError: FIELD_NOT_ALLOWED_ERROR, } sentry_ignored_errors = ( @@ -177,4 +180,9 @@ def format_error(error): if "code" not in formatted_error["extensions"]: formatted_error["extensions"]["code"] = error_code + if error_code == FIELD_NOT_ALLOWED_ERROR: + formatted_error["extensions"]["field_name"] = getattr( + error.original_error, "field_name", "" + ) + return formatted_error