Skip to content

Handle mandatory components in recipe JSON smoothly #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 10, 2022

Conversation

christianlupus
Copy link
Collaborator

Closes #923

This introduces a new possible status in the case of storing a recipe (both new and existing). If the name was empty, the recipe could not be stored and thus a 406 is returned by the server.

It can easily be extended for other mandatory entries in the recipe description.

@christianlupus
Copy link
Collaborator Author

This PR just focuses on the backend part. The mentioned frontend issues as suggested in #923 with red border and subtext etc must be implemented in the frontend. This is considered an additional feature and should be handled in a dedicated feature request.

@codecov
Copy link

codecov bot commented May 2, 2022

Codecov Report

Merging #973 (a1fdac6) into master (fb8be79) will increase coverage by 0.63%.
The diff coverage is 93.75%.

❗ Current head a1fdac6 differs from pull request most recent head 14a5ff5. Consider uploading reports for the commit 14a5ff5 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #973      +/-   ##
==========================================
+ Coverage   28.95%   29.59%   +0.63%     
==========================================
  Files          30       31       +1     
  Lines        1547     1561      +14     
==========================================
+ Hits          448      462      +14     
  Misses       1099     1099              
Flag Coverage Δ
integration 5.44% <0.00%> (-0.05%) ⬇️
unittests 24.15% <93.75%> (+0.68%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/Controller/MainController.php 100.00% <ø> (ø)
lib/Service/RecipeService.php 0.00% <0.00%> (ø)
lib/Controller/RecipeController.php 95.52% <100.00%> (+0.97%) ⬆️
lib/Exception/NoRecipeNameGivenException.php 100.00% <100.00%> (ø)

Signed-off-by: Christian Wolf <[email protected]>
@github-actions
Copy link

github-actions bot commented May 2, 2022

Unit Test Results

     24 files       24 suites   8m 38s ⏱️
   122 tests    122 ✔️ 0 💤 0
1 464 runs  1 464 ✔️ 0 💤 0

Results for commit 14a5ff5.

♻️ This comment has been updated with latest results.

@christianlupus christianlupus requested a review from seyfeb May 7, 2022 18:33
'file' => $ex->getFile(),
'line' => $ex->getLine(),
];
return new JSONResponse($json, Http::STATUS_NOT_ACCEPTABLE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the correct status code to return here? Isn’t this more like a 400?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. 400 seems more suited. I do not like the 400 as it is items used as a catch all code. But we do not use it currently as far as I know.

I will update soon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood your intention, but looking through the 4xx error codes on https://developer.mozilla.org/en-US/docs/Web/HTTP/Status only 422 seemed suited but is restricted to WebDAV. we could misuse it though to have a more specific code...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer the 400 or the 422? I'd maybe even go for the 422 as we are building the API in any case. So I would maybe even vote for 422. I will wait with merging for your thoughts.

We can of course say that for that specific endpoint (/api/recipe/<id>/image) the 400 is sufficient and we provide an error message as well...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d support either way, take your pick ;)

@christianlupus christianlupus requested a review from seyfeb May 10, 2022 06:04
Signed-off-by: Christian Wolf <[email protected]>
@christianlupus christianlupus merged commit f1cec2e into master May 10, 2022
@delete-merged-branch delete-merged-branch bot deleted the fix/923-unknown-name-exception branch May 10, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhelpful error message Unknown answer returned from server. See logs. given if recipe name missing
2 participants