Skip to content

Commit

Permalink
feat: add FieldNotAllowedError
Browse files Browse the repository at this point in the history
Refs HP-2319
  • Loading branch information
nicobav committed May 23, 2024
1 parent 803c0ea commit da711f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions open_city_profile/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions open_city_profile/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions open_city_profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,6 +36,7 @@
ConnectedServiceDeletionFailedError,
ConnectedServiceDeletionNotAllowedError,
DataConflictError,
FieldNotAllowedError,
InsufficientLoaError,
InvalidEmailFormatError,
MissingGDPRApiTokenError,
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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

0 comments on commit da711f1

Please sign in to comment.