fix(FastAPI): add custom error templates for certain exceptions

Signed-off-by: Steven Guikal <void@fluix.one>
This commit is contained in:
Steven Guikal 2021-12-13 19:08:33 -05:00 committed by Kevin Morris
parent 51b60f4210
commit e126d431d7
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
4 changed files with 70 additions and 4 deletions

View file

@ -87,11 +87,14 @@ def provides_markup(provides: Providers) -> str:
def get_pkg_or_base(
name: str,
cls: Union[models.Package, models.PackageBase] = models.PackageBase):
cls: Union[models.Package, models.PackageBase] = models.PackageBase) \
-> Union[models.Package, models.PackageBase]:
""" Get a PackageBase instance by its name or raise a 404 if
it can't be found in the database.
:param name: {Package,PackageBase}.Name
:param exception: Whether to raise an HTTPException or simply return None if
the package can't be found.
:raises HTTPException: With status code 404 if record doesn't exist
:return: {Package,PackageBase} instance
"""