Skip to content

Commit 29be0e8

Browse files
authored
chore: start using the FastAPI version and other cleanup (#256)
* Set the current version in the FastAPI constructor and use `app.version` elsewhere * Update version-sync commands accordingly * Do not dump stack traces for unhandled errors * Add a startup log, other startup is silent without `uvicorn.error`
1 parent 9bd7e52 commit 29be0e8

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 0.0.48-dev0
1+
## 0.0.48
22

3-
* **Adds `languages` kwarg** `ocr_languages` will eventually be depricated and replaced by `lanugages` to specify what languages to use for OCR
3+
* **Adds `languages` kwarg** `ocr_languages` will eventually be deprecated and replaced by `lanugages` to specify what languages to use for OCR
4+
* Adds a startup log and other minor cleanups
45

56
## 0.0.47
67

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ check-version:
130130
scripts/version-sync.sh -c \
131131
-s CHANGELOG.md \
132132
-f preprocessing-pipeline-family.yaml release \
133-
-f ${PACKAGE_NAME}/api/general.py release
133+
-f ${PACKAGE_NAME}/api/app.py release
134134

135135
## version-sync: update references to version with most recent version from CHANGELOG.md
136136
.PHONY: version-sync
137137
version-sync:
138138
scripts/version-sync.sh \
139139
-s CHANGELOG.md \
140140
-f preprocessing-pipeline-family.yaml release \
141-
-f ${PACKAGE_NAME}/api/general.py release
141+
-f ${PACKAGE_NAME}/api/app.py release

prepline_general/api/app.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from fastapi import FastAPI, Request, status, HTTPException
22
from fastapi.responses import JSONResponse
3-
import json
43
import logging
54
import os
6-
import traceback
75

86
from .general import router as general_router
97

@@ -13,7 +11,7 @@
1311
app = FastAPI(
1412
title="Unstructured Pipeline API",
1513
description="""""",
16-
version="1.0.0",
14+
version="0.0.48",
1715
docs_url="/general/docs",
1816
openapi_url="/general/openapi.json",
1917
)
@@ -28,26 +26,13 @@
2826
@app.exception_handler(HTTPException)
2927
async def http_error_handler(request: Request, e: HTTPException):
3028
logger.error(e.detail)
31-
3229
return JSONResponse(status_code=e.status_code, content={"detail": e.detail})
3330

3431

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
3733
@app.exception_handler(Exception)
3834
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)})
5136

5237

5338
allowed_origins = os.environ.get("ALLOWED_ORIGINS", None)
@@ -83,3 +68,6 @@ def filter(self, record: logging.LogRecord) -> bool:
8368
@app.get("/healthcheck", status_code=status.HTTP_200_OK, include_in_schema=False)
8469
def healthcheck(request: Request):
8570
return {"healthcheck": "HEALTHCHECK STATUS: EVERYTHING OK!"}
71+
72+
73+
logger.info("Started Unstructured API")

prepline_general/api/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def return_content_type(filename):
569569

570570

571571
@router.post("/general/v0/general")
572-
@router.post("/general/v0.0.48/general")
572+
@router.post(f"/general/v{app.version}/general")
573573
def pipeline_1(
574574
request: Request,
575575
gz_uncompressed_content_type: Optional[str] = Form(default=None),

0 commit comments

Comments
 (0)