|
1 | 1 | from fastapi import FastAPI, Request, status, HTTPException |
2 | 2 | from fastapi.responses import JSONResponse |
3 | | -import json |
4 | 3 | import logging |
5 | 4 | import os |
6 | | -import traceback |
7 | 5 |
|
8 | 6 | from .general import router as general_router |
9 | 7 |
|
|
13 | 11 | app = FastAPI( |
14 | 12 | title="Unstructured Pipeline API", |
15 | 13 | description="""""", |
16 | | - version="1.0.0", |
| 14 | + version="0.0.48", |
17 | 15 | docs_url="/general/docs", |
18 | 16 | openapi_url="/general/openapi.json", |
19 | 17 | ) |
|
28 | 26 | @app.exception_handler(HTTPException) |
29 | 27 | async def http_error_handler(request: Request, e: HTTPException): |
30 | 28 | logger.error(e.detail) |
31 | | - |
32 | 29 | return JSONResponse(status_code=e.status_code, content={"detail": e.detail}) |
33 | 30 |
|
34 | 31 |
|
35 | | -# Note(austin) - Convert any other errors to HTTPException |
36 | | -# to be handled above, and log the stack trace |
| 32 | +# Catch any other errors and return as 500 |
37 | 33 | @app.exception_handler(Exception) |
38 | 34 | async def error_handler(request: Request, e: Exception): |
39 | | - trace = traceback.format_exc() |
40 | | - |
41 | | - # Note(austin) - If ENV is set, dump the stack in json |
42 | | - # for nicer parsing. Soon we'll just have a json logger do this. |
43 | | - if os.environ.get("ENV") in ["dev", "prod"]: |
44 | | - trace = json.dumps(trace) |
45 | | - |
46 | | - logger.error(trace) |
47 | | - |
48 | | - error = HTTPException(status_code=500, detail=str(e)) |
49 | | - |
50 | | - return await http_error_handler(request, error) |
| 35 | + return JSONResponse(status_code=500, content={"detail": str(e)}) |
51 | 36 |
|
52 | 37 |
|
53 | 38 | allowed_origins = os.environ.get("ALLOWED_ORIGINS", None) |
@@ -83,3 +68,6 @@ def filter(self, record: logging.LogRecord) -> bool: |
83 | 68 | @app.get("/healthcheck", status_code=status.HTTP_200_OK, include_in_schema=False) |
84 | 69 | def healthcheck(request: Request): |
85 | 70 | return {"healthcheck": "HEALTHCHECK STATUS: EVERYTHING OK!"} |
| 71 | + |
| 72 | + |
| 73 | +logger.info("Started Unstructured API") |
0 commit comments