feat: app rate limit (#5844)
Co-authored-by: liuzhenghua-jk <liuzhenghua-jk@360shuke.com> Co-authored-by: takatost <takatost@gmail.com>
This commit is contained in:
parent
cc8dc6d35e
commit
9622fbb62f
19 changed files with 277 additions and 56 deletions
|
|
@ -6,6 +6,8 @@ from flask_restful import Api, http_status_message
|
|||
from werkzeug.datastructures import Headers
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from core.errors.error import AppInvokeQuotaExceededError
|
||||
|
||||
|
||||
class ExternalApi(Api):
|
||||
|
||||
|
|
@ -43,6 +45,13 @@ class ExternalApi(Api):
|
|||
'message': str(e),
|
||||
'status': status_code
|
||||
}
|
||||
elif isinstance(e, AppInvokeQuotaExceededError):
|
||||
status_code = 429
|
||||
default_data = {
|
||||
'code': 'too_many_requests',
|
||||
'message': str(e),
|
||||
'status': status_code
|
||||
}
|
||||
else:
|
||||
status_code = 500
|
||||
default_data = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue