aury-boot 0.0.21__py3-none-any.whl → 0.0.22__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.
aury/boot/_version.py CHANGED
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.21'
32
- __version_tuple__ = version_tuple = (0, 0, 21)
31
+ __version__ = version = '0.0.22'
32
+ __version_tuple__ = version_tuple = (0, 0, 22)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -11,10 +11,10 @@ from contextlib import asynccontextmanager
11
11
  import sys
12
12
  from typing import Any, ClassVar
13
13
 
14
- from fastapi import FastAPI, HTTPException, Request, status
14
+ from fastapi import FastAPI, Request, status
15
15
  from fastapi.exceptions import RequestValidationError
16
16
  from fastapi.responses import JSONResponse
17
- from starlette.exceptions import HTTPException as StarletteHTTPException
17
+ from starlette.exceptions import HTTPException
18
18
  from starlette.middleware import Middleware as StarletteMiddleware
19
19
 
20
20
  from aury.boot.application.config import BaseConfig
@@ -282,9 +282,8 @@ class FoundationApp(FastAPI):
282
282
  )
283
283
 
284
284
  # 异常处理:显式注册以覆盖 FastAPI/Starlette 默认处理器,确保统一响应格式
285
- self.add_exception_handler(RequestValidationError, global_exception_handler) # 422
286
- self.add_exception_handler(HTTPException, global_exception_handler) # 4xx/5xx
287
- self.add_exception_handler(StarletteHTTPException, global_exception_handler) # Starlette 异常
285
+ self.add_exception_handler(RequestValidationError, global_exception_handler) # 422 参数校验
286
+ self.add_exception_handler(HTTPException, global_exception_handler) # 4xx/5xx HTTP 异常
288
287
  self.add_exception_handler(Exception, global_exception_handler) # 其他未处理异常
289
288
 
290
289
  # 设置路由
@@ -8,11 +8,12 @@ from __future__ import annotations
8
8
  from abc import ABC, abstractmethod
9
9
  from typing import TYPE_CHECKING
10
10
 
11
- from fastapi import HTTPException, Request, status
11
+ from fastapi import Request, status
12
12
  from fastapi.exceptions import RequestValidationError
13
13
  from fastapi.responses import JSONResponse
14
14
  from pydantic import ValidationError
15
15
  from sqlalchemy.exc import IntegrityError, SQLAlchemyError
16
+ from starlette.exceptions import HTTPException
16
17
 
17
18
  from aury.boot.common.exceptions import FoundationError
18
19
  from aury.boot.common.logging import logger
@@ -149,23 +150,31 @@ class BaseErrorHandler(ErrorHandler):
149
150
 
150
151
 
151
152
  class HTTPExceptionHandler(ErrorHandler):
152
- """FastAPI HTTP异常处理器。"""
153
+ """HTTP 异常处理器。
154
+
155
+ 处理 FastAPI 和 Starlette 的 HTTPException(包括 404、401、403 等)。
156
+ """
153
157
 
154
158
  def can_handle(self, exception: Exception) -> bool:
155
- """判断是否为HTTP异常。"""
159
+ """判断是否为 HTTP 异常。"""
160
+ # Starlette HTTPException 是 FastAPI HTTPException 的基类
156
161
  return isinstance(exception, HTTPException)
157
162
 
158
163
  async def handle(self, exception: HTTPException, request: Request) -> JSONResponse:
159
- """处理HTTP异常。"""
160
- logger.warning(f"HTTP异常: {exception.status_code} - {exception.detail}")
164
+ """处理 HTTP 异常。"""
165
+ # 获取错误信息:Starlette detail,FastAPI 也用 detail
166
+ detail = getattr(exception, "detail", str(exception))
167
+ status_code = exception.status_code
168
+
169
+ logger.warning(f"HTTP 异常 [{request.method} {request.url.path}]: {status_code} - {detail}")
161
170
 
162
171
  response = ResponseBuilder.fail(
163
- message=exception.detail,
164
- code=exception.status_code,
172
+ message=detail if isinstance(detail, str) else str(detail),
173
+ code=status_code,
165
174
  )
166
175
 
167
176
  return JSONResponse(
168
- status_code=exception.status_code,
177
+ status_code=status_code,
169
178
  content=response.model_dump(mode="json"),
170
179
  )
171
180
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aury-boot
3
- Version: 0.0.21
3
+ Version: 0.0.22
4
4
  Summary: Aury Boot - 基于 FastAPI 生态的企业级 API 开发框架
5
5
  Requires-Python: >=3.13
6
6
  Requires-Dist: alembic>=1.17.2
@@ -1,5 +1,5 @@
1
1
  aury/boot/__init__.py,sha256=pCno-EInnpIBa1OtxNYF-JWf9j95Cd2h6vmu0xqa_-4,1791
2
- aury/boot/_version.py,sha256=G-x3V64IYobhRYKCOse2hTj6uYLM7_2kyUMOZMY7cf4,706
2
+ aury/boot/_version.py,sha256=ppqXAvMQkDCf5uPK5J4O6hozIheDimMJFhFAaY9euV0,706
3
3
  aury/boot/application/__init__.py,sha256=0o_XmiwFCeAu06VHggS8I1e7_nSMoRq0Hcm0fYfCywU,3071
4
4
  aury/boot/application/adapter/__init__.py,sha256=e1bcSb1bxUMfofTwiCuHBZJk5-STkMCWPF2EJXHQ7UU,3976
5
5
  aury/boot/application/adapter/base.py,sha256=Ar_66fiHPDEmV-1DKnqXKwc53p3pozG31bgTJTEUriY,15763
@@ -8,7 +8,7 @@ aury/boot/application/adapter/decorators.py,sha256=yyGu_16bWWUiO36gxCeQWgG0DN19p
8
8
  aury/boot/application/adapter/exceptions.py,sha256=Kzm-ytRxdUnSMIcWCSOHPxo4Jh_A6YbyxlOVIUs-5F4,6183
9
9
  aury/boot/application/adapter/http.py,sha256=4TADsSzdSRU63307dmmo-2U_JpVP12mwTFy66B5Ps-w,10759
10
10
  aury/boot/application/app/__init__.py,sha256=I8FfCKDuDQsGzAK6BevyfdtAwieMUVYu6qgVQzBazpE,830
11
- aury/boot/application/app/base.py,sha256=PYYUC_Yz3U885aU2uG5EAbbKOj_oUB4VSYMD_KS5i1s,17789
11
+ aury/boot/application/app/base.py,sha256=MYfkrb2zZgumLrGWhtT71neGncUfVHyUeAHRnetoSXk,17668
12
12
  aury/boot/application/app/components.py,sha256=-blDjMF87GYFmFyk4DHm2KJDcm27HpMxGpNaEFluwEE,22403
13
13
  aury/boot/application/app/middlewares.py,sha256=BXe2H14FHzJUVpQM6DZUm-zfZRXSXIi1QIZ4_3izfHw,3306
14
14
  aury/boot/application/app/startup.py,sha256=DHKt3C2G7V5XfFr1SQMl14tNzcuDd9MqUVAxi274HDQ,7873
@@ -23,7 +23,7 @@ aury/boot/application/errors/__init__.py,sha256=aYhGqjHayYr7sv9kM22y0sOo9R-8RK0r
23
23
  aury/boot/application/errors/chain.py,sha256=DSLZvPH7oNcxE26j3hiXG_1W7-3fdKyu0QMEEi1c5CY,2306
24
24
  aury/boot/application/errors/codes.py,sha256=CBR8umCSNp1zUslwK9tboQ4s753qBwA1OpefaQTPdjE,1431
25
25
  aury/boot/application/errors/exceptions.py,sha256=5gHC9cQsuvNpO5V9GlFkb-QqH0xNqQaOKBmTBM5wYEI,7303
26
- aury/boot/application/errors/handlers.py,sha256=Q9U1YK_tzO2lWtLhJ4Tuq973vyuCm_zElYEO07DoYlk,11948
26
+ aury/boot/application/errors/handlers.py,sha256=K6bL-ktKgzB_VCdKIL4VmQw4Z5srYRy3NJbbfnmzh_g,12367
27
27
  aury/boot/application/errors/response.py,sha256=fqOO3bNTnRRjoN3gK0-6xBVAYfSqyPvUbONowAecq9k,3107
28
28
  aury/boot/application/interfaces/__init__.py,sha256=EGbiCL8IoGseylLVZO29Lkt3luygG7JknTgtAxeb48U,1438
29
29
  aury/boot/application/interfaces/egress.py,sha256=t8FK17V649rsm65uAeBruYr2mhfcqJiIzkS8UPsOzlc,5346
@@ -192,7 +192,7 @@ aury/boot/testing/client.py,sha256=KOg1EemuIVsBG68G5y0DjSxZGcIQVdWQ4ASaHE3o1R0,4
192
192
  aury/boot/testing/factory.py,sha256=8GvwX9qIDu0L65gzJMlrWB0xbmJ-7zPHuwk3eECULcg,5185
193
193
  aury/boot/toolkit/__init__.py,sha256=AcyVb9fDf3CaEmJPNkWC4iGv32qCPyk4BuFKSuNiJRQ,334
194
194
  aury/boot/toolkit/http/__init__.py,sha256=zIPmpIZ9Qbqe25VmEr7jixoY2fkRbLm7NkCB9vKpg6I,11039
195
- aury_boot-0.0.21.dist-info/METADATA,sha256=a7scICE4EqlEjn1ZsnemOzEscg8IySfO6WV6VQKO-_s,7695
196
- aury_boot-0.0.21.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
197
- aury_boot-0.0.21.dist-info/entry_points.txt,sha256=f9KXEkDIGc0BGkgBvsNx_HMz9VhDjNxu26q00jUpDwQ,49
198
- aury_boot-0.0.21.dist-info/RECORD,,
195
+ aury_boot-0.0.22.dist-info/METADATA,sha256=ni5jJsNSu861N3iwbJndJrniPtKLU3U7kEa1CVNDNwA,7695
196
+ aury_boot-0.0.22.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
197
+ aury_boot-0.0.22.dist-info/entry_points.txt,sha256=f9KXEkDIGc0BGkgBvsNx_HMz9VhDjNxu26q00jUpDwQ,49
198
+ aury_boot-0.0.22.dist-info/RECORD,,