Skip to content

Instantly share code, notes, and snippets.

@Montgoner
Created February 19, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Montgoner/bb2fd5e98eb807829d9601581471cab6 to your computer and use it in GitHub Desktop.
Save Montgoner/bb2fd5e98eb807829d9601581471cab6 to your computer and use it in GitHub Desktop.
LATEST_API_VERSION = APIVersion(major_version=1, minor_version=1)
# Create app object and add routes
app = FastAPI(title="My Item App")
app.include_router(unversioned_router)
app.include_router(router_v1_0)
app.include_router(router_v1_1)
exception_handlers = {
500: internal_error_exception_handler, # Uncontrolled internal server errors (e.g. raised by FastAPI's middlewares)
CustomServiceError: internal_error_exception_handler, # Controlled internal server errors
RequestValidationError: request_validation_exception_handler, # Custom data validation error
}
app = version_app(app, default_api_version=LATEST_API_VERSION, exception_handlers=exception_handlers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment