BLOG-100 User retrieval functionality in authentication module #102

Merged
squid merged 1 commits from BLOG-100_get_current_logged_in_user into main 2025-08-01 18:42:22 +08:00
Owner

Description

  • Endpoint: GET /me, returns the whole user data.

Package Changes

No response

Screenshots

No response

Reference

Resolves #100

Checklist

  • A milestone is set
  • The related issuse has been linked to this branch
### Description - Endpoint: GET `/me`, returns the whole user data. ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #100 ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch
squid added this to the 0.3 milestone 2025-08-01 18:39:54 +08:00
squid added 1 commit 2025-08-01 18:39:54 +08:00
BLOG-100 feat: user retrieval functionality in authentication module
All checks were successful
Frontend CI / build (push) Successful in 1m10s
Auto Comment On PR / add_improve_comment (pull_request) Successful in 17s
PR Title Check / pr-title-check (pull_request) Successful in 17s
6c1b970953
Collaborator

/improve

/improve
Collaborator

PR Code Suggestions

CategorySuggestion                                                                                                                                    Impact
Possible issue
Return specific HTTP error codes

The current error handling returns a generic 500 Internal Server Error for all
AuthError variants. If AuthError::UserNotFound occurs, a 404 Not Found response
would be more semantically appropriate for the client. Differentiate error responses
based on the specific AuthError variant.

backend/feature/auth/src/framework/web/auth_web_routes.rs [110-116]

 match result {
     Ok(user) => HttpResponse::Ok().json(user),
+    Err(AuthError::UserNotFound) => HttpResponse::NotFound().finish(),
     Err(e) => {
         log::error!("{e:?}");
         HttpResponse::InternalServerError().finish()
     }
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that returning a generic 500 for AuthError::UserNotFound is not ideal. Providing a specific 404 response for AuthError::UserNotFound improves the API's semantic correctness and client-side error handling.

Medium
## PR Code Suggestions ✨ <!-- --> <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>Possible issue</td> <td> <details><summary>Return specific HTTP error codes</summary> ___ **The current error handling returns a generic 500 Internal Server Error for all <br><code>AuthError</code> variants. If <code>AuthError::UserNotFound</code> occurs, a 404 Not Found response <br>would be more semantically appropriate for the client. Differentiate error responses <br>based on the specific <code>AuthError</code> variant.** [backend/feature/auth/src/framework/web/auth_web_routes.rs [110-116]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-100_get_current_logged_in_user/backend/feature/auth/src/framework/web/auth_web_routes.rs#L110-L116) ```diff match result { Ok(user) => HttpResponse::Ok().json(user), + Err(AuthError::UserNotFound) => HttpResponse::NotFound().finish(), Err(e) => { log::error!("{e:?}"); HttpResponse::InternalServerError().finish() } } ``` <details><summary>Suggestion importance[1-10]: 8</summary> __ Why: The suggestion correctly identifies that returning a generic 500 for `AuthError::UserNotFound` is not ideal. Providing a specific 404 response for `AuthError::UserNotFound` improves the API's semantic correctness and client-side error handling. </details></details></td><td align=center>Medium </td></tr></tr></tbody></table>
Author
Owner

The current error handling returns a generic 500 Internal Server Error for all
AuthError variants. If AuthError::UserNotFound occurs, a 404 Not Found response
would be more semantically appropriate for the client. Differentiate error responses
based on the specific AuthError variant.

backend/feature/auth/src/framework/web/auth_web_routes.rs [110-116]

 match result {
     Ok(user) => HttpResponse::Ok().json(user),
+    Err(AuthError::UserNotFound) => HttpResponse::NotFound().finish(),
     Err(e) => {
         log::error!("{e:?}");
         HttpResponse::InternalServerError().finish()
     }
 }

Since NotFound error isn't expected in this situation, returns InternalError.

> **The current error handling returns a generic 500 Internal Server Error for all <br><code>AuthError</code> variants. If <code>AuthError::UserNotFound</code> occurs, a 404 Not Found response <br>would be more semantically appropriate for the client. Differentiate error responses <br>based on the specific <code>AuthError</code> variant.** > > [backend/feature/auth/src/framework/web/auth_web_routes.rs [110-116]](https://git.squidspirit.com/squid/blog/src/branch/BLOG-100_get_current_logged_in_user/backend/feature/auth/src/framework/web/auth_web_routes.rs#L110-L116) > > ```diff > match result { > Ok(user) => HttpResponse::Ok().json(user), > + Err(AuthError::UserNotFound) => HttpResponse::NotFound().finish(), > Err(e) => { > log::error!("{e:?}"); > HttpResponse::InternalServerError().finish() > } > } > ``` Since `NotFound` error isn't expected in this situation, returns `InternalError`.
squid merged commit f986810540 into main 2025-08-01 18:42:22 +08:00
squid deleted branch BLOG-100_get_current_logged_in_user 2025-08-01 18:42:22 +08:00
Sign in to join this conversation.
No description provided.