14 lines
434 B
Python
14 lines
434 B
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
from rest_framework.exceptions import Throttled
|
||
|
|
from rest_framework.views import exception_handler
|
||
|
|
|
||
|
|
from apps.api.errors import api_error
|
||
|
|
|
||
|
|
|
||
|
|
def api_exception_handler(exc, context):
|
||
|
|
response = exception_handler(exc, context)
|
||
|
|
if response is not None and isinstance(exc, Throttled):
|
||
|
|
response.data = api_error("rate_limited", "请求过于频繁,请稍后再试")
|
||
|
|
return response
|