summary refs log tree commit diff
path: root/synapse/api/errors.py
diff options
context:
space:
mode:
authorWill Hunt <will@half-shot.uk>2018-07-09 13:31:21 +0000
committerGitHub <noreply@github.com>2018-07-09 13:31:21 +0000
commita7f4ebbd3e786ce2e156127a3806aa2594233542 (patch)
treec73795182b60fcc17a5e5b13864eb84758d96c29 /synapse/api/errors.py
parent/limits => /config (diff)
parentMerge pull request #3464 from matrix-org/hawkowl/isort-run (diff)
downloadsynapse-a7f4ebbd3e786ce2e156127a3806aa2594233542.tar.xz
Merge branch 'develop' into hs/upload-limits
Diffstat (limited to 'synapse/api/errors.py')
-rw-r--r--synapse/api/errors.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py

index a9ff5576f3..6074df292f 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py
@@ -17,8 +17,10 @@ import logging -import simplejson as json from six import iteritems +from six.moves import http_client + +from canonicaljson import json logger = logging.getLogger(__name__) @@ -51,6 +53,8 @@ class Codes(object): THREEPID_DENIED = "M_THREEPID_DENIED" INVALID_USERNAME = "M_INVALID_USERNAME" SERVER_NOT_TRUSTED = "M_SERVER_NOT_TRUSTED" + CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN" + CANNOT_LEAVE_SERVER_NOTICE_ROOM = "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM" class CodeMessageException(RuntimeError): @@ -138,6 +142,32 @@ class SynapseError(CodeMessageException): return res +class ConsentNotGivenError(SynapseError): + """The error returned to the client when the user has not consented to the + privacy policy. + """ + def __init__(self, msg, consent_uri): + """Constructs a ConsentNotGivenError + + Args: + msg (str): The human-readable error message + consent_url (str): The URL where the user can give their consent + """ + super(ConsentNotGivenError, self).__init__( + code=http_client.FORBIDDEN, + msg=msg, + errcode=Codes.CONSENT_NOT_GIVEN + ) + self._consent_uri = consent_uri + + def error_dict(self): + return cs_error( + self.msg, + self.errcode, + consent_uri=self._consent_uri + ) + + class RegistrationError(SynapseError): """An error raised when a registration event fails.""" pass @@ -292,7 +322,7 @@ def cs_error(msg, code=Codes.UNKNOWN, **kwargs): Args: msg (str): The error message. - code (int): The error code. + code (str): The error code. kwargs : Additional keys to add to the response. Returns: A dict representing the error response JSON.