nlbone 0.7.29__py3-none-any.whl → 0.7.30__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,7 +60,8 @@ def install_exception_handlers(
60
60
  "http_error",
61
61
  extra={"status": exc.status_code, "detail": exc.detail, "path": request.url.path},
62
62
  )
63
- return _json_response(request, exc.status_code, detail=_(exc.detail))
63
+ locale = locale = getattr(request.state, "locale", None)
64
+ return _json_response(request, exc.status_code, detail=_(exc.detail, locale=locale))
64
65
 
65
66
  @app.exception_handler(FastAPIHTTPException)
66
67
  async def _handle_fastapi_http_exception(request: Request, exc: FastAPIHTTPException):
@@ -69,7 +70,8 @@ def install_exception_handlers(
69
70
  "fastapi_http_error",
70
71
  extra={"status": exc.status_code, "detail": exc.detail, "path": request.url.path},
71
72
  )
72
- return _json_response(request, exc.status_code, detail=exc.detail)
73
+ locale = locale = getattr(request.state, "locale", None)
74
+ return _json_response(request, exc.status_code, detail=_(exc.detail, locale=locale))
73
75
 
74
76
  @app.exception_handler(StarletteHTTPException)
75
77
  async def _handle_starlette_http_exception(request: Request, exc: StarletteHTTPException):
@@ -78,7 +80,8 @@ def install_exception_handlers(
78
80
  "starlette_http_error",
79
81
  extra={"status": exc.status_code, "detail": exc.detail, "path": request.url.path},
80
82
  )
81
- return _json_response(request, exc.status_code, detail=exc.detail)
83
+ locale = locale = getattr(request.state, "locale", None)
84
+ return _json_response(request, exc.status_code, detail=_(exc.detail, locale=locale))
82
85
 
83
86
  # 3) خطاهای اعتبارسنجی FastAPI (request body/query/path)
84
87
  @app.exception_handler(RequestValidationError)
@@ -107,4 +110,5 @@ def install_exception_handlers(
107
110
  if logger:
108
111
  logger.exception("unhandled_exception", extra={"trace_id": tid, "path": request.url.path})
109
112
  detail = str(exc) if expose_server_errors else "internal server error"
110
- return _json_response(request, 500, detail=detail, trace_id=tid)
113
+ locale = locale = getattr(request.state, "locale", None)
114
+ return _json_response(request, 500, detail=_(detail, locale=locale), trace_id=tid)
@@ -99,3 +99,10 @@ class GoneException(BaseHttpException):
99
99
  status_code=status.HTTP_410_GONE,
100
100
  detail=detail,
101
101
  )
102
+
103
+ class TooManyRequestsException(BaseHttpException):
104
+ def __init__(self, detail: str = "TooManyRequests"):
105
+ super().__init__(
106
+ status_code=status.HTTP_429_TOO_MANY_REQUESTS,
107
+ detail=detail,
108
+ )
@@ -46,6 +46,7 @@ class AddRequestContextMiddleware(BaseHTTPMiddleware):
46
46
  ip = request.client.host if request.client else None
47
47
  ua = request.headers.get("user-agent")
48
48
  locale = request.headers.get("Accept-Language", 'fa-IR')
49
+ request.state.locale = locale
49
50
 
50
51
  tokens = bind_context(request=request, request_id=req_id, user_id=user_id, ip=ip, user_agent=ua, locale=locale)
51
52
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nlbone
3
- Version: 0.7.29
3
+ Version: 0.7.30
4
4
  Summary: Backbone package for interfaces and infrastructure in Python projects
5
5
  Author-email: Amir Hosein Kahkbazzadeh <a.khakbazzadeh@gmail.com>
6
6
  License: MIT
@@ -70,8 +70,8 @@ nlbone/core/ports/translation.py,sha256=pnqbxhdRCR7eprm8UI8ZKKx7VDUPntvBtlytrnTG
70
70
  nlbone/core/ports/uow.py,sha256=VhqSc-Ryt9m-rlNMiXTzD3dPGz6mM_JxND8D0UJGRu4,962
71
71
  nlbone/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
72
  nlbone/interfaces/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
- nlbone/interfaces/api/exception_handlers.py,sha256=pk7ehq15fZ6If57BvDjo_Ot-R5hTEFMhBP5KDwp61AM,4102
74
- nlbone/interfaces/api/exceptions.py,sha256=Phv0nXaEHCgJVEAuQ2q8QHxpn_diXahKarupSHOATY0,2964
73
+ nlbone/interfaces/api/exception_handlers.py,sha256=jH2VAgx63auFSat1H3uQ0Z9JrJ6YYN57dFuqwKzT7EU,4431
74
+ nlbone/interfaces/api/exceptions.py,sha256=06S677YplJgODjVaa3fP00dPy9i-bNIlDWg1t5Q8EZc,3194
75
75
  nlbone/interfaces/api/routers.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  nlbone/interfaces/api/schemas.py,sha256=NIEKeTdJtwwIkIxL7WURNZF8g34I4TlRAqs-x1Uq7YI,108
77
77
  nlbone/interfaces/api/additional_filed/__init__.py,sha256=BWemliLSQV9iq1vdUaF733q0FOSipSWBOQk9eYj732Q,318
@@ -88,7 +88,7 @@ nlbone/interfaces/api/dependencies/db.py,sha256=-UD39J_86UU7ZJs2ZncpdND0yhAG0Nee
88
88
  nlbone/interfaces/api/dependencies/uow.py,sha256=QfLEvLYLNWZJQN1k-0q0hBVtUld3D75P4j39q_RjcnE,1181
89
89
  nlbone/interfaces/api/middleware/__init__.py,sha256=zbX2vaEAfxRMIYwO2MVY_2O6bqG5H9o7HqGpX14U3Is,158
90
90
  nlbone/interfaces/api/middleware/access_log.py,sha256=vIkxxxfy2HcjqqKb8XCfGCcSrivAC8u6ie75FMq5x-U,1032
91
- nlbone/interfaces/api/middleware/add_request_context.py,sha256=rRxsE34XvsefN3HufZQyXqPFzCeWhdn3qel0-cS2QZM,1914
91
+ nlbone/interfaces/api/middleware/add_request_context.py,sha256=o8mdo-D6fODM9OyHunE5UodkVxsh4F__5tDv8ju8Sxg,1952
92
92
  nlbone/interfaces/api/middleware/authentication.py,sha256=Bt6sYu4KtXAyUQnSIp-Z2Z1yKNNtfRy9Y3rOZcYTFhw,3299
93
93
  nlbone/interfaces/api/pagination/__init__.py,sha256=pA1uC4rK6eqDI5IkLVxmgO2B6lExnOm8Pje2-hifJZw,431
94
94
  nlbone/interfaces/api/pagination/offset_base.py,sha256=60X8a9uDOSd3qG45M49dqNG_FUjSxEDrgEyb9JD9V-o,4113
@@ -114,8 +114,8 @@ nlbone/utils/http.py,sha256=0yeI34j5FfelqvX3PJnKknSXji1jl15VYbVIIvrSbXg,997
114
114
  nlbone/utils/normalize_mobile.py,sha256=sGH4tV9gX-6eVKozviNWJhm1DN1J28Nj-ERldCYkS_E,732
115
115
  nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
116
116
  nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
117
- nlbone-0.7.29.dist-info/METADATA,sha256=BjeBTqBMp4Ob1lqx8s8ihRQ5URDcY3e-P8sc5hTyaxY,2295
118
- nlbone-0.7.29.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
119
- nlbone-0.7.29.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
120
- nlbone-0.7.29.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
121
- nlbone-0.7.29.dist-info/RECORD,,
117
+ nlbone-0.7.30.dist-info/METADATA,sha256=1Mt2PMc8gNgSKNuHrH-LjPnQ3k2b7yiK67r4n_7yXqA,2295
118
+ nlbone-0.7.30.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
119
+ nlbone-0.7.30.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
120
+ nlbone-0.7.30.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
121
+ nlbone-0.7.30.dist-info/RECORD,,