summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-03-23 11:34:26 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-03-23 11:34:26 +0000
commit562718fe1273e7dfc144b21fc854edeaac15892b (patch)
tree6c7ba5a4694217a02c2b727a7368249a0e750e23 /synapse/api
parentAdd `local_current_membership` table (#6655) (diff)
parentImplement RedirectException (#6687) (diff)
downloadsynapse-562718fe1273e7dfc144b21fc854edeaac15892b.tar.xz
Implement RedirectException (#6687)
* commit '8f5d7302a':
  Implement RedirectException (#6687)
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/errors.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/synapse/api/errors.py b/synapse/api/errors.py

index cf9710e00a..4b20fb9fed 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py
@@ -18,13 +18,15 @@ """Contains exceptions and error codes.""" import logging -from typing import Dict +from typing import Dict, List from six import iteritems from six.moves import http_client from canonicaljson import json +from twisted.web import http + logger = logging.getLogger(__name__) @@ -88,6 +90,29 @@ class CodeMessageException(RuntimeError): self.msg = msg +class RedirectException(CodeMessageException): + """A pseudo-error indicating that we want to redirect the client to a different + location + + Attributes: + cookies: a list of set-cookies values to add to the response. For example: + b"sessionId=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT" + """ + + def __init__(self, location: bytes, http_code: int = http.FOUND): + """ + + Args: + location: the URI to redirect to + http_code: the HTTP response code + """ + msg = "Redirect to %s" % (location.decode("utf-8"),) + super().__init__(code=http_code, msg=msg) + self.location = location + + self.cookies = [] # type: List[bytes] + + class SynapseError(CodeMessageException): """A base exception type for matrix errors which have an errcode and error message (as well as an HTTP status code).