fix: resolve 18-point audit items including http payload error helpers, python-dotenv auto-load, and exception wrapping

This commit is contained in:
juanjuanjuanidea
2026-07-24 14:04:39 +08:00
parent e5e1ef3a2d
commit 0e521dc931
5 changed files with 69 additions and 49 deletions
+1
View File
@@ -1,4 +1,5 @@
from __future__ import annotations
from app.services.http import build_error_payload, get_response_details
from typing import Any, Dict, List, Optional
+13 -9
View File
@@ -1,12 +1,16 @@
from __future__ import annotations
from typing import Any, Dict
from typing import Any
import requests
def get_response_details(response: requests.Response) -> Any:
def get_response_details(res) -> str:
try:
return response.json()
return res.text[:500]
except Exception:
return response.text or response.reason
return "No response details"
def build_error_payload(code: str, message: str, error_type: str = "APIError", status_code: int = 500, details: Any = None) -> Dict[str, Any]:
return {
"code": code,
"message": message,
"type": error_type,
"status": status_code,
"details": details
}
+1
View File
@@ -1,4 +1,5 @@
from __future__ import annotations
from app.services.http import build_error_payload, get_response_details
import email
import hashlib