'Make a SynapseError based on an HTTPResponseException
This is useful when a proxied request has failed, and we need to
decide how to map the failure onto a matrix error to send back to the
client.
An attempt is made to parse the body of the http response as a matrix
error. If that succeeds, the errcode and error message from the body
are used as the errcode and error message in the new synapse error.
Otherwise, the errcode is set to M_UNKNOWN, and the error message is
set to the reason code from the HTTP response.
Args:
err (HttpResponseException):
Returns:
SynapseError:'

@classmethod
def from_http_response_exception(cls, err):

    try:
        j = json.loads(err.response)
    except ValueError:
        j = {}
    errcode = j.get('errcode', Codes.UNKNOWN)
    errmsg = j.get('error', err.msg)
    res = SynapseError(err.code, errmsg, errcode)
    return res
