Add BaseAPIException handling to invoice routes for improved error management

This commit is contained in:
2026-05-08 14:12:31 -05:00
parent 9e3274b03a
commit 6113c47839

View File

@@ -3,6 +3,7 @@ from typing import Dict, Any, Optional
from core.config import settings
from core.database import get_core_db
from core.exceptions import BaseAPIException
from core.security import collect_user_role_names, get_current_user, validate_access_to_resource
from fastapi import APIRouter, Depends, HTTPException, Query, Path
from sqlalchemy import func, or_, and_
@@ -69,6 +70,8 @@ def get_creation_data(
return InvoiceCatalogService.get_creation_data(db, tenant_id, company_id)
except HTTPException:
raise
except BaseAPIException:
raise
except Exception as e:
logger.exception("get_creation_data failed: %s", e)
raise HTTPException(status_code=500, detail=f"Error al cargar datos de creación: {str(e)}")
@@ -97,6 +100,8 @@ def get_edition_data(
return data
except HTTPException:
raise
except BaseAPIException:
raise
except Exception as e:
logger.exception("get_edition_data failed: %s", e)
raise HTTPException(status_code=500, detail=f"Error al cargar datos de edición: {str(e)}")
@@ -191,6 +196,8 @@ def create_invoice(
return services.InvoiceService.create(db, data, tenant_id, company_id)
except HTTPException:
raise
except BaseAPIException:
raise
except Exception as e:
logger.exception("create_invoice failed: %s", e)
raise HTTPException(status_code=500, detail=f"Error al guardar factura: {str(e)}")
@@ -337,6 +344,8 @@ def list_invoices(
"page": page,
"page_size": page_size
}
except BaseAPIException:
raise
except Exception as e:
logger.exception("list_invoices failed: %s", e)
raise HTTPException(status_code=500, detail=f"Internal server error in invoices list: {str(e)}")