33 lines
1018 B
Python
33 lines
1018 B
Python
from fastapi import FastAPI, Request
|
||
from fastapi.responses import JSONResponse
|
||
import logging
|
||
from routers import profile, jobs
|
||
|
||
|
||
# Инициализация приложения
|
||
|
||
app = FastAPI(
|
||
title="linkedin API",
|
||
description="API с linkedin получаем данные по URL",
|
||
version="1.0.0")
|
||
|
||
|
||
# Подключение роутеров
|
||
app.include_router(profile.router, tags=["Profile"])
|
||
app.include_router(jobs.router, tags=["Jobs"])
|
||
|
||
|
||
|
||
# Проверка состояния сервера
|
||
@app.get("/", tags=["Check"])
|
||
async def check():
|
||
return {"status": "ok"}
|
||
|
||
# Глобальный middleware для обработки необработанных исключений
|
||
@app.middleware("http")
|
||
async def catch_exceptions_middleware(request: Request, call_next):
|
||
try:
|
||
return await call_next(request)
|
||
except Exception as e:
|
||
logging.error(f"Unhandled exception: {str(e)}")
|
||
return JSONResponse(content={"error": "Internal Server Error"}, status_code=500) |