mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
Retrieve the missing field from the API request, use in errors
Signed-off-by: Litchi Pi <litchi.pi@proton.me>
This commit is contained in:
parent
c002b2051c
commit
f289171ce1
3 changed files with 6 additions and 5 deletions
|
@ -52,5 +52,6 @@ class IncompleteData(Exception):
|
||||||
"""
|
"""
|
||||||
This exception is raised when a user sends incomplete data to the API
|
This exception is raised when a user sends incomplete data to the API
|
||||||
"""
|
"""
|
||||||
|
def __init__(self, missing, *args, **kwargs):
|
||||||
pass
|
Exception.__init__(*args, **kwargs):
|
||||||
|
self.missing = missing
|
||||||
|
|
|
@ -85,10 +85,10 @@ class RecipeController(BaseRecipeController):
|
||||||
self.logger.error("No Entry Found on recipe controller action")
|
self.logger.error("No Entry Found on recipe controller action")
|
||||||
raise HTTPException(status_code=404, detail=ErrorResponse.respond(message="No Entry Found"))
|
raise HTTPException(status_code=404, detail=ErrorResponse.respond(message="No Entry Found"))
|
||||||
elif thrownType == exceptions.IncompleteData:
|
elif thrownType == exceptions.IncompleteData:
|
||||||
self.logger.error("Incomplete data provided to API route")
|
self.logger.error("Incomplete data provided to API route:", ex.missing)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
detail=ErrorResponse.respond(message="Some data were missing on the body of this API request"),
|
detail=ErrorResponse.respond(message=f"Field '{ex.missing}' missing on the body of this API request"),
|
||||||
)
|
)
|
||||||
elif thrownType == sqlalchemy.exc.IntegrityError:
|
elif thrownType == sqlalchemy.exc.IntegrityError:
|
||||||
self.logger.error("SQL Integrity Error on recipe controller action")
|
self.logger.error("SQL Integrity Error on recipe controller action")
|
||||||
|
|
|
@ -393,7 +393,7 @@ class RecipeService(RecipeServiceBase):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if getattr(new_data, field) is None:
|
if getattr(new_data, field) is None:
|
||||||
raise exceptions.IncompleteData(f"Incomplete recipe, missing {field}")
|
raise exceptions.IncompleteData(field, f"Incomplete recipe, missing {field}")
|
||||||
|
|
||||||
if recipe is None or recipe.settings is None:
|
if recipe is None or recipe.settings is None:
|
||||||
raise exceptions.NoEntryFound("Recipe not found.")
|
raise exceptions.NoEntryFound("Recipe not found.")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue