Use CodeMessageException subclass instead

Parse json errors from get_json client methods and throw special
errors.
This commit is contained in:
David Baker 2017-04-25 19:30:55 +01:00
parent a46982cee9
commit 1a9255c12e
4 changed files with 51 additions and 61 deletions

View file

@ -66,6 +66,17 @@ class CodeMessageException(RuntimeError):
return cs_error(self.msg)
class MatrixCodeMessageException(CodeMessageException):
"""An error from a general matrix endpoint, eg. from a proxied Matrix API call.
Attributes:
errcode (str): Matrix error code e.g 'M_FORBIDDEN'
"""
def __init__(self, code, msg, errcode=Codes.UNKNOWN):
super(MatrixCodeMessageException, self).__init__(code, msg)
self.errcode = errcode
class SynapseError(CodeMessageException):
"""A base exception type for matrix errors which have an errcode and error
message (as well as an HTTP status code).