31 lines
763 B
Python
31 lines
763 B
Python
from fastapi import FastAPI, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.api.v1.location import router as location_router
|
|
|
|
app = FastAPI(title="CargoTrace API", version="0.1.0")
|
|
|
|
app.include_router(location_router, prefix="/CargoTrace")
|
|
|
|
|
|
@app.exception_handler(ValueError)
|
|
async def value_error_handler(request: Request, exc: ValueError):
|
|
error_code = str(exc)
|
|
status_map = {
|
|
"INVALID_ZONGPAI": 400,
|
|
"INVALID_LOCATION": 400,
|
|
}
|
|
status = status_map.get(error_code, 400)
|
|
return JSONResponse(
|
|
status_code=status,
|
|
content={
|
|
"error_code": error_code,
|
|
"message": str(exc),
|
|
},
|
|
)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Welcome to CargoTrace API"}
|