Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
683596f9
Commit
683596f9
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Raise LimitExceedError when the ratelimiting is throttling requests
parent
780548b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/api/errors.py
+27
-7
27 additions, 7 deletions
synapse/api/errors.py
synapse/handlers/_base.py
+2
-4
2 additions, 4 deletions
synapse/handlers/_base.py
with
29 additions
and
11 deletions
synapse/api/errors.py
+
27
−
7
View file @
683596f9
...
...
@@ -40,10 +40,13 @@ class CodeMessageException(Exception):
self
.
code
=
code
self
.
msg
=
msg
def
error_dict
(
self
):
return
cs_error
(
self
.
msg
)
class
SynapseError
(
CodeMessageException
):
"""
A base error which can be caught for all synapse events.
"""
def
__init__
(
self
,
code
,
msg
,
errcode
=
""
):
def
__init__
(
self
,
code
,
msg
,
errcode
=
Codes
.
UNKNOWN
):
"""
Constructs a synapse error.
Args:
...
...
@@ -54,6 +57,11 @@ class SynapseError(CodeMessageException):
super
(
SynapseError
,
self
).
__init__
(
code
,
msg
)
self
.
errcode
=
errcode
def
error_dict
(
self
):
return
cs_error
(
self
.
msg
,
self
.
errcode
,
)
class
RoomError
(
SynapseError
):
"""
An error raised when a room event fails.
"""
...
...
@@ -92,13 +100,25 @@ class StoreError(SynapseError):
pass
def
cs_exception
(
exception
):
if
isinstance
(
exception
,
SynapseError
):
class
LimitExceededError
(
SynapseError
):
"""
A client has sent too many requests and is being throttled.
"""
def
__init__
(
self
,
code
=
429
,
msg
=
"
Too Many Requests
"
,
retry_after_ms
=
None
,
errcode
=
Codes
.
LIMIT_EXCEEDED
):
super
(
LimitExceededError
,
self
).
__init__
(
code
,
msg
,
errcode
)
self
.
retry_after_ms
=
retry_after_ms
def
error_dict
(
self
):
return
cs_error
(
exception
.
msg
,
Codes
.
UNKNOWN
if
not
exception
.
errcode
else
exception
.
errcode
)
elif
isinstance
(
exception
,
CodeMessageException
):
return
cs_error
(
exception
.
msg
)
self
.
msg
,
self
.
errcode
,
retry_after_ms
=
self
.
retry_after_ms
,
)
def
cs_exception
(
exception
):
if
isinstance
(
exception
,
CodeMessageException
):
return
exception
.
error_dict
()
else
:
logging
.
error
(
"
Unknown exception type: %s
"
,
type
(
exception
))
...
...
This diff is collapsed.
Click to expand it.
synapse/handlers/_base.py
+
2
−
4
View file @
683596f9
...
...
@@ -14,7 +14,7 @@
# limitations under the License.
from
twisted.internet
import
defer
from
synapse.api.errors
import
cs_error
,
Codes
from
synapse.api.errors
import
LimitExceededError
class
BaseHandler
(
object
):
...
...
@@ -38,9 +38,7 @@ class BaseHandler(object):
burst_count
=
self
.
hs
.
config
.
rc_message_burst_count
,
)
if
not
allowed
:
raise
cs_error
(
"
Limit exceeded
"
,
Codes
.
LIMIT_EXCEEDED
,
raise
LimitExceededError
(
retry_after_ms
=
1000
*
(
time_allowed
-
time_now
),
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment