.
This commit is contained in:
parent
2412f4ae2b
commit
24676fab2b
@ -5,7 +5,7 @@ from dotenv import load_dotenv
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
conn_str = (
|
conn_str = (
|
||||||
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
|
f"DRIVER={{SQL Server}};"
|
||||||
f"SERVER={os.getenv('MSSQL_SERVER')};"
|
f"SERVER={os.getenv('MSSQL_SERVER')};"
|
||||||
f"DATABASE={os.getenv('MSSQL_DATABASE')};"
|
f"DATABASE={os.getenv('MSSQL_DATABASE')};"
|
||||||
f"UID={os.getenv('MSSQL_USERNAME')};"
|
f"UID={os.getenv('MSSQL_USERNAME')};"
|
||||||
|
|||||||
12
main.py
12
main.py
@ -2,6 +2,7 @@ import random
|
|||||||
import string
|
import string
|
||||||
import pyodbc
|
import pyodbc
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from fastapi import FastAPI, HTTPException, Depends, Query
|
from fastapi import FastAPI, HTTPException, Depends, Query
|
||||||
from typing import List
|
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 contants import NOME_PROGETTO, MESSAGGIO_SUCCESSO,API_SECRET_KEY,VALUTA,FL_SCOR,TIPO_RIGA_ART,FL_OMAG
|
||||||
from datetime import datetime
|
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()
|
app = FastAPI()
|
||||||
|
|
||||||
def genera_codice_random(lunghezza: int = 50) -> str:
|
def genera_codice_random(lunghezza: int = 50) -> str:
|
||||||
@ -218,9 +226,11 @@ def crea_ordine(ordine: OrdineTestata):
|
|||||||
|
|
||||||
except pyodbc.Error as e:
|
except pyodbc.Error as e:
|
||||||
conn.rollback()
|
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)}")
|
raise HTTPException(status_code=500, detail=f"Errore DB: {str(e)}")
|
||||||
|
|
||||||
except Exception as 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)}")
|
raise HTTPException(status_code=500, detail=f"Errore generico: {str(e)}")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -228,4 +238,4 @@ def crea_ordine(ordine: OrdineTestata):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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