.
This commit is contained in:
parent
2412f4ae2b
commit
24676fab2b
@ -5,7 +5,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
conn_str = (
|
||||
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
|
||||
f"DRIVER={{SQL Server}};"
|
||||
f"SERVER={os.getenv('MSSQL_SERVER')};"
|
||||
f"DATABASE={os.getenv('MSSQL_DATABASE')};"
|
||||
f"UID={os.getenv('MSSQL_USERNAME')};"
|
||||
|
||||
12
main.py
12
main.py
@ -2,6 +2,7 @@ import random
|
||||
import string
|
||||
import pyodbc
|
||||
import uvicorn
|
||||
import logging
|
||||
import os
|
||||
from fastapi import FastAPI, HTTPException, Depends, Query
|
||||
from typing import List
|
||||
@ -14,6 +15,13 @@ from models import (
|
||||
from contants import NOME_PROGETTO, MESSAGGIO_SUCCESSO,API_SECRET_KEY,VALUTA,FL_SCOR,TIPO_RIGA_ART,FL_OMAG
|
||||
from datetime import datetime
|
||||
|
||||
# Log config
|
||||
logging.basicConfig(
|
||||
filename='api_errors.log',
|
||||
level=logging.ERROR, # You can change to DEBUG or INFO as needed
|
||||
format='%(asctime)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
def genera_codice_random(lunghezza: int = 50) -> str:
|
||||
@ -218,9 +226,11 @@ def crea_ordine(ordine: OrdineTestata):
|
||||
|
||||
except pyodbc.Error as e:
|
||||
conn.rollback()
|
||||
logging.error("Errore DB durante la creazione dell'ordine", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=f"Errore DB: {str(e)}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Errore generico durante la creazione dell'ordine", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail=f"Errore generico: {str(e)}")
|
||||
|
||||
finally:
|
||||
@ -228,4 +238,4 @@ def crea_ordine(ordine: OrdineTestata):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=os.getenv('PORTA_API'))
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
Loading…
Reference in New Issue
Block a user