Skip to content

Comments

feat: add handling for missing cookie in token and update error messages#1078

Merged
ThinuwanW merged 3 commits intodevelopfrom
fix/proper-error-for-cookies
Feb 20, 2026
Merged

feat: add handling for missing cookie in token and update error messages#1078
ThinuwanW merged 3 commits intodevelopfrom
fix/proper-error-for-cookies

Conversation

@akilarootcode
Copy link
Contributor

PR checklist

TaskId: (https://github.com/SkappHQ/skapp/issues/[id])

Summary

How to test

Project Checklist

  • Changes build without any errors
  • Have written adequate test cases
  • Done developer testing in
    • Chrome
    • Firefox
    • Safari
  • Code is formatted with npm run format
  • Code is linted with npm run check-lint
  • No unnecessary comments left in code
  • Made corresponding changes to the documentation

Other

  • New atomic components added
  • New molecules added
  • New pages(routes) added
  • New dependencies installed

PR Checklist

  • Pull request is raised from the correct source branch
  • Pull request is raised to the correct destination branch
  • Pull request is raised with correct title
  • Pull request is self reviewed
  • Pull request is self assigned
  • Suitable pull request status labels are added (ready-for-code-review)

Additional Information

@akilarootcode akilarootcode self-assigned this Feb 19, 2026
Copilot AI review requested due to automatic review settings February 19, 2026 17:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a dedicated global exception mapping for missing refresh-token cookies so session-based token refresh requests return a clearer, localized error response instead of falling back to generic handling.

Changes:

  • Added a new common message key/value for “missing cookie in token” scenarios.
  • Introduced a MissingRequestCookieException handler in GlobalExceptionHandler returning a 401 response.
  • Added a corresponding enum constant to CommonMessageConstant.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
backend/src/main/resources/community/messages/common-messages.properties Adds a new localized error message for missing refresh-token cookie scenarios.
backend/src/main/java/com/skapp/community/common/exception/GlobalExceptionHandler.java Handles MissingRequestCookieException and returns a standardized 401 error payload.
backend/src/main/java/com/skapp/community/common/constant/CommonMessageConstant.java Adds a new message constant referencing the new properties key.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 216 to 225
@ExceptionHandler(MissingRequestCookieException.class)
public ResponseEntity<ResponseEntityDto> handleMissingRequestCookieException(MissingRequestCookieException e) {
HttpStatus status = HttpStatus.UNAUTHORIZED;
String message = messageUtil.getMessage(CommonMessageConstant.COMMON_ERROR_MISSING_COOKIE_IN_TOKEN);
logDetailedException(e, CommonMessageConstant.COMMON_ERROR_MISSING_COOKIE_IN_TOKEN.name(), message, status);

return new ResponseEntity<>(
new ResponseEntityDto(true,
new ErrorResponse(status, message, CommonMessageConstant.COMMON_ERROR_MISSING_COOKIE_IN_TOKEN)),
status);
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

This handler returns a fixed message for missing cookies, but MissingRequestCookieException provides the actual missing cookie name. Since this is a global handler, hardcoding refreshToken in the message will become misleading if any other endpoint later requires a different cookie. Consider parameterizing the message (e.g., using {0} in the properties file) and passing e.getCookieName() via messageUtil.getMessage(..., new Object[]{...}) so the response stays accurate.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 216 to 220
@ExceptionHandler(MissingRequestCookieException.class)
public ResponseEntity<ResponseEntityDto> handleMissingRequestCookieException(MissingRequestCookieException e) {
HttpStatus status = HttpStatus.UNAUTHORIZED;
String message = messageUtil.getMessage(CommonMessageConstant.COMMON_ERROR_MISSING_COOKIE_IN_TOKEN);
logDetailedException(e, CommonMessageConstant.COMMON_ERROR_MISSING_COOKIE_IN_TOKEN.name(), message, status);
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

New behavior is introduced for missing refreshToken cookie requests, but there is no corresponding integration test coverage. Add an AuthController integration test for POST /v1/auth/session/refresh-token without the refreshToken cookie asserting the 401 response and the expected error payload/message key, to prevent regressions.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need

@sonarqubecloud
Copy link

@ThinuwanW ThinuwanW merged commit 3f050a7 into develop Feb 20, 2026
3 of 4 checks passed
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.

2 participants