Skip to content

Comments

Fix ProfileApi error handling for invalid usernames (MDD-79)#371

Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1771876499-mdd79-profile-error-handling
Open

Fix ProfileApi error handling for invalid usernames (MDD-79)#371
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1771876499-mdd79-profile-error-handling

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Feb 23, 2026

Fix ProfileApi error handling for invalid usernames (MDD-79)

Summary

Adds an explicit @ExceptionHandler for ResourceNotFoundException in CustomizeExceptionHandler so that 404 responses include a JSON body ({"message": "Profile not found"}) instead of an empty response. Previously, Spring Boot's default 404 handling kicked in with no body, causing frontends to show a generic "Something went wrong" message.

Also adds a test in ProfileApiTest verifying that following a nonexistent user returns 404 with the expected message.

Review & Testing Checklist for Human

  • The error message "Profile not found" is hardcoded for all ResourceNotFoundException usages — this exception is also thrown by ArticleApi, ArticleFavoriteApi, CommentsApi, and several GraphQL resolvers. A missing article or comment will incorrectly return "Profile not found". Verify whether this is acceptable or if the message should be made generic (e.g. "Resource not found") or derived from the exception.
  • Verify the response format {"message": "..."} meets frontend expectations (no errors wrapper, etc.)
  • Manually test GET /api/profiles/null, POST /api/profiles/null/follow, and DELETE /api/profiles/null/follow to confirm all three return the expected 404 body end-to-end.

Notes


Open with Devin

Add explicit exception handler for ResourceNotFoundException in
CustomizeExceptionHandler to return a JSON body with a descriptive
error message instead of an empty 404 response. This fixes the
generic 'Something went wrong' error shown to users when following
profiles with invalid usernames.

Also add test coverage for the 404 scenario in ProfileApiTest.

MDD-79

Co-Authored-By: unknown <>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<Object> handleResourceNotFound(
ResourceNotFoundException e, WebRequest request) {
return ResponseEntity.status(NOT_FOUND).body(Map.of("message", "Profile not found"));
Copy link
Author

Choose a reason for hiding this comment

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

🔴 Hardcoded "Profile not found" message returned for all ResourceNotFoundException usages, not just profiles

The new @ExceptionHandler for ResourceNotFoundException hardcodes the response body as {"message": "Profile not found"}, but ResourceNotFoundException is thrown across many different API controllers and GraphQL resolvers — not just ProfileApi.

Affected callers and impact

ResourceNotFoundException is thrown from:

  • ArticleApi.java:41,62,78 — when an article is not found by slug
  • CommentsApi.java:46,57,73,84 — when an article or comment is not found
  • ArticleFavoriteApi.java:33,43 — when an article is not found for favoriting
  • ProfileApi.java:34,48,64,66 — when a profile/user is not found
  • Multiple GraphQL resolvers (ArticleMutation, CommentMutation, ArticleDatafetcher, RelationMutation, ProfileDatafetcher, MeDatafetcher)

For example, when a client requests GET /articles/nonexistent-slug, the ArticleApi throws ResourceNotFoundException, and the handler will return:

{"message": "Profile not found"}

instead of something accurate like "Article not found" or a generic "Resource not found".

Impact: All non-profile 404 responses will contain a misleading error message, confusing API consumers and frontend error displays.

Suggested change
return ResponseEntity.status(NOT_FOUND).body(Map.of("message", "Profile not found"));
return ResponseEntity.status(NOT_FOUND).body(Map.of("message", "Resource not found"));
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant