diff options
author | Neil Johnson <neil@fragile.org.uk> | 2018-05-14 09:31:42 +0100 |
---|---|---|
committer | Neil Johnson <neil@fragile.org.uk> | 2018-05-14 09:31:42 +0100 |
commit | 977765bde2987770f63065d839f9686a7a144140 (patch) | |
tree | 41d3a247f546cfe50500f465e50a798a597ef464 /synapse/http/__init__.py | |
parent | remove user agent from data model, will just join on user_ips (diff) | |
parent | Merge pull request #2846 from kaiyou/feat-dockerfile (diff) | |
download | synapse-977765bde2987770f63065d839f9686a7a144140.tar.xz |
Merge branch 'develop' of https://github.com/matrix-org/synapse into cohort_analytics
Diffstat (limited to 'synapse/http/__init__.py')
-rw-r--r-- | synapse/http/__init__.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/synapse/http/__init__.py b/synapse/http/__init__.py index bfebb0f644..054372e179 100644 --- a/synapse/http/__init__.py +++ b/synapse/http/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2014-2016 OpenMarket Ltd +# Copyright 2018 New Vector Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,3 +13,24 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from twisted.internet.defer import CancelledError +from twisted.python import failure + +from synapse.api.errors import SynapseError + + +class RequestTimedOutError(SynapseError): + """Exception representing timeout of an outbound request""" + def __init__(self): + super(RequestTimedOutError, self).__init__(504, "Timed out") + + +def cancelled_to_request_timed_out_error(value, timeout): + """Turns CancelledErrors into RequestTimedOutErrors. + + For use with async.add_timeout_to_deferred + """ + if isinstance(value, failure.Failure): + value.trap(CancelledError) + raise RequestTimedOutError() + return value |