Skip to content

Comments

fix(WEB-10910): improve image upload error handling in PostController#628

Merged
ammbot merged 3 commits intomainfrom
thanya/web-10910
Dec 25, 2025
Merged

fix(WEB-10910): improve image upload error handling in PostController#628
ammbot merged 3 commits intomainfrom
thanya/web-10910

Conversation

@ammbot
Copy link
Contributor

@ammbot ammbot commented Dec 23, 2025

Edge Cases

  • When post is not found, now returns 404 with explicit error message instead of 400
  • Existing 400 error for invalid changeset remains unchanged
  • All existing image upload functionality preserved

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Code Quality

  • Added docs
  • Added specs

- Simplified the image upload logic using a `with` statement for better readability.
- Updated error handling to return a 404 response when the post is not found, instead of a 400 response.
- Added a test case to verify that a 404 response is returned when attempting to upload an image for a non-existent post.
@ammbot ammbot added enhancement New feature or request elixir Pull requests that update Elixir code labels Dec 23, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @ammbot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on refining the error handling within the PostController's image upload functionality. The primary goal is to provide more precise feedback to the client when a post targeted for image upload cannot be located, by returning a 404 status code instead of a generic 400. This change improves the API's clarity and diagnostic capabilities without altering the successful image upload flow or existing invalid changeset error responses.

Highlights

  • Improved Error Handling: The upload_image function in PostController now explicitly returns a 404 Not Found status with a clear 'Post not found' error message when an image upload is attempted for a non-existent post. Previously, this scenario might have resulted in a less specific 400 Bad Request.
  • Code Refactoring: The upload_image function has been refactored to utilize Elixir's with statement, enhancing readability and providing a more structured approach to handling sequential operations and their potential error outcomes.
  • New Test Coverage: A new test case has been added to PostControllerTest to specifically verify the new 404 error response when an image upload is attempted for a post that does not exist, ensuring the improved error handling works as expected.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ammbot ammbot requested a review from jdamanalo December 23, 2025 04:23
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.09%. Comparing base (99a3979) to head (b24d524).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/literature/controllers/post_controller.ex 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #628      +/-   ##
==========================================
+ Coverage   78.06%   78.09%   +0.02%     
==========================================
  Files          84       84              
  Lines        2375     2378       +3     
==========================================
+ Hits         1854     1857       +3     
  Misses        521      521              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the error handling in the PostController's upload_image function. The refactoring to use a with statement is a great choice, making the code cleaner and more robust by explicitly handling the case where a post is not found and returning a 404 error. The addition of a corresponding test case ensures this new behavior is verified. I have one suggestion to further refactor the code to reduce duplication, which will improve maintainability.

@ammbot ammbot requested a review from samhamilton December 23, 2025 04:30
@ammbot ammbot changed the title refactor(WEB-10910): improve image upload error handling in PostController fix(WEB-10910): improve image upload error handling in PostController Dec 23, 2025
@ammbot ammbot added bug Something isn't working and removed enhancement New feature or request labels Dec 23, 2025
@ammbot ammbot requested review from hendri-tobing and removed request for samhamilton December 23, 2025 04:34
@ammbot ammbot merged commit 6c783fa into main Dec 25, 2025
14 checks passed
@ammbot ammbot deleted the thanya/web-10910 branch December 25, 2025 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working elixir Pull requests that update Elixir code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants