From 8d6ec2b4335121fd35f256a4e4d1a6693e7e8012 Mon Sep 17 00:00:00 2001 From: Yerish26 Date: Mon, 13 May 2024 23:48:46 +0400 Subject: [PATCH 1/4] edit title validation added --- .../constraint/TitleConstraintValidator.java | 33 +++++++++++++++++++ .../llm_service/constraint/ValidTitle.java | 27 +++++++++++++++ .../conversation/ConversationController.java | 21 ++++++++++-- .../ConversationTitleRequest.java | 2 ++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/com/llm_service/llm_service/constraint/TitleConstraintValidator.java create mode 100644 backend/src/main/java/com/llm_service/llm_service/constraint/ValidTitle.java diff --git a/backend/src/main/java/com/llm_service/llm_service/constraint/TitleConstraintValidator.java b/backend/src/main/java/com/llm_service/llm_service/constraint/TitleConstraintValidator.java new file mode 100644 index 0000000..51c4f40 --- /dev/null +++ b/backend/src/main/java/com/llm_service/llm_service/constraint/TitleConstraintValidator.java @@ -0,0 +1,33 @@ +package com.llm_service.llm_service.constraint; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class TitleConstraintValidator implements ConstraintValidator { + + private int min; + private int max; + + @Override + public void initialize(ValidTitle constraintAnnotation) { + this.min = constraintAnnotation.min(); + this.max = constraintAnnotation.max(); + } + + @Override + public boolean isValid(String title, ConstraintValidatorContext context) { + if (title == null) { + return true; + } + + int length = title.length(); + if (length < min || length > max) { + String errorMessage = "Title length must be between " + min + " and " + max + " characters"; + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation(); + return false; + } + + return true; + } +} diff --git a/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTitle.java b/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTitle.java new file mode 100644 index 0000000..3c58b64 --- /dev/null +++ b/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTitle.java @@ -0,0 +1,27 @@ +package com.llm_service.llm_service.constraint; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Documented +@Constraint(validatedBy = TitleConstraintValidator.class) +@Target({FIELD}) +@Retention(RUNTIME) +public @interface ValidTitle { + + String message() default "Title length must be between {min} and {max} characters"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + int min() default 3; + + int max() default 30; +} diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java index c43a3a1..408b56a 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java @@ -1,5 +1,6 @@ package com.llm_service.llm_service.controller.conversation; +import com.llm_service.llm_service.controller.user.ValidationErrorResponse; import com.llm_service.llm_service.dto.Conversation; import com.llm_service.llm_service.dto.Discussion; import com.llm_service.llm_service.exception.UnAuthorizedException; @@ -9,11 +10,15 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import jakarta.validation.Valid; +import java.util.HashMap; import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; import org.springframework.web.bind.annotation.*; @RestController @@ -99,8 +104,20 @@ public ResponseEntity> continueConversation( }) @Operation(summary = "update conversation title") @PutMapping("/api/v1/conversation/{id}") - public ResponseEntity editConversation( - @PathVariable UUID id, @RequestBody ConversationTitleRequest conversationTitleRequest) throws Exception { + public ResponseEntity editConversation( + @PathVariable UUID id, + @Valid @RequestBody ConversationTitleRequest conversationTitleRequest, + BindingResult bindingResult) + throws Exception { + + if (bindingResult.hasErrors()) { + ValidationErrorResponse errorResponse = new ValidationErrorResponse(new HashMap<>()); + for (FieldError error : bindingResult.getFieldErrors()) { + errorResponse.addError(error.getField(), error.getDefaultMessage()); + } + return ResponseEntity.badRequest().body(errorResponse); + } + Conversation conversation = conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); conversation = conversationService.editTitle(conversation, conversationTitleRequest.getTitle()); diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationTitleRequest.java b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationTitleRequest.java index 3d67fea..2d84e84 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationTitleRequest.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationTitleRequest.java @@ -1,5 +1,6 @@ package com.llm_service.llm_service.controller.conversation; +import com.llm_service.llm_service.constraint.ValidTitle; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -10,5 +11,6 @@ @Jacksonized public class ConversationTitleRequest { @NonNull + @ValidTitle String title; } From cf1ae03c5ac91955e12a2d180f9694b5fd469c20 Mon Sep 17 00:00:00 2001 From: Yerish26 Date: Tue, 14 May 2024 00:09:42 +0400 Subject: [PATCH 2/4] continue conversation validation added --- .../TextLengthConstraintValidator.java | 28 ++++++++++++ .../constraint/ValidTextLength.java | 25 +++++++++++ .../conversation/ConversationController.java | 44 ++++++++++++------- .../conversation/ConversationRequest.java | 2 + .../controller/user/UserController.java | 7 +-- .../user => dto}/ValidationErrorResponse.java | 2 +- .../exception/UnAuthorizedException.java | 7 --- .../exception/UnauthorizedException.java | 7 +++ .../service/ConversationService.java | 22 +++++----- 9 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 backend/src/main/java/com/llm_service/llm_service/constraint/TextLengthConstraintValidator.java create mode 100644 backend/src/main/java/com/llm_service/llm_service/constraint/ValidTextLength.java rename backend/src/main/java/com/llm_service/llm_service/{controller/user => dto}/ValidationErrorResponse.java (91%) delete mode 100644 backend/src/main/java/com/llm_service/llm_service/exception/UnAuthorizedException.java create mode 100644 backend/src/main/java/com/llm_service/llm_service/exception/UnauthorizedException.java diff --git a/backend/src/main/java/com/llm_service/llm_service/constraint/TextLengthConstraintValidator.java b/backend/src/main/java/com/llm_service/llm_service/constraint/TextLengthConstraintValidator.java new file mode 100644 index 0000000..f3d71e9 --- /dev/null +++ b/backend/src/main/java/com/llm_service/llm_service/constraint/TextLengthConstraintValidator.java @@ -0,0 +1,28 @@ +package com.llm_service.llm_service.constraint; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class TextLengthConstraintValidator implements ConstraintValidator { + + private int min; + + @Override + public void initialize(ValidTextLength constraintAnnotation) { + this.min = constraintAnnotation.min(); + } + + @Override + public boolean isValid(String text, ConstraintValidatorContext context) { + if (text == null) { + return true; + } + if (text.length() < min) { + String errorMessage = "Text length must be at least " + min + " characters"; + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation(); + return false; + } + return true; + } +} diff --git a/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTextLength.java b/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTextLength.java new file mode 100644 index 0000000..9baf3f9 --- /dev/null +++ b/backend/src/main/java/com/llm_service/llm_service/constraint/ValidTextLength.java @@ -0,0 +1,25 @@ +package com.llm_service.llm_service.constraint; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Documented +@Constraint(validatedBy = TextLengthConstraintValidator.class) +@Target({FIELD}) +@Retention(RUNTIME) +public @interface ValidTextLength { + + String message() default "Text length must be at least {min} characters"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + int min() default 5; +} diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java index 408b56a..20328ed 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java @@ -1,9 +1,9 @@ package com.llm_service.llm_service.controller.conversation; -import com.llm_service.llm_service.controller.user.ValidationErrorResponse; import com.llm_service.llm_service.dto.Conversation; import com.llm_service.llm_service.dto.Discussion; -import com.llm_service.llm_service.exception.UnAuthorizedException; +import com.llm_service.llm_service.dto.ValidationErrorResponse; +import com.llm_service.llm_service.exception.UnauthorizedException; import com.llm_service.llm_service.exception.conversation.ConversationNotFoundException; import com.llm_service.llm_service.service.ConversationService; import io.swagger.v3.oas.annotations.Operation; @@ -15,6 +15,7 @@ import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.Nullable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.BindingResult; @@ -38,7 +39,7 @@ public class ConversationController { }) @Operation(summary = "Get all conversations") @GetMapping(value = "/api/v1/paid/conversation") - public ResponseEntity> getAllConversations() throws UnAuthorizedException { + public ResponseEntity> getAllConversations() throws UnauthorizedException { return ResponseEntity.ok(conversationService.getAll().stream() .map(conversationApiMapper::mapCompact) .toList()); @@ -54,7 +55,7 @@ public ResponseEntity> getAllConversations() t @Operation(summary = "Get conversation by ID") @GetMapping("/api/v1/conversation/{id}") public ResponseEntity getConversationById(@PathVariable UUID id) - throws ConversationNotFoundException, UnAuthorizedException { + throws ConversationNotFoundException, UnauthorizedException { Conversation conversation = conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); @@ -85,9 +86,13 @@ public ResponseEntity createConversation() throws Exceptio }) @Operation(summary = "Continue conversation using conversation ID") @PutMapping("/api/v1/conversation/{id}/continue") - public ResponseEntity> continueConversation( - @PathVariable UUID id, @RequestBody ConversationRequest conversationRequest) - throws ConversationNotFoundException, UnAuthorizedException { + public ResponseEntity continueConversation( + @PathVariable UUID id, + @Valid @RequestBody ConversationRequest conversationRequest, + BindingResult bindingResult) + throws ConversationNotFoundException, UnauthorizedException { + ResponseEntity errorResponse = getValidationErrorResponseResponseEntity(bindingResult); + if (errorResponse != null) return errorResponse; Conversation conversation = conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); List discussions = conversationService.askLlmQuestion(conversation, conversationRequest.getText()); @@ -110,6 +115,18 @@ public ResponseEntity editConversation( BindingResult bindingResult) throws Exception { + ResponseEntity errorResponse = getValidationErrorResponseResponseEntity(bindingResult); + if (errorResponse != null) return errorResponse; + + Conversation conversation = + conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); + conversation = conversationService.editTitle(conversation, conversationTitleRequest.getTitle()); + + return ResponseEntity.status(HttpStatus.OK).body(conversationApiMapper.mapCompact(conversation)); + } + + private static @Nullable ResponseEntity getValidationErrorResponseResponseEntity( + BindingResult bindingResult) { if (bindingResult.hasErrors()) { ValidationErrorResponse errorResponse = new ValidationErrorResponse(new HashMap<>()); for (FieldError error : bindingResult.getFieldErrors()) { @@ -117,12 +134,7 @@ public ResponseEntity editConversation( } return ResponseEntity.badRequest().body(errorResponse); } - - Conversation conversation = - conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); - conversation = conversationService.editTitle(conversation, conversationTitleRequest.getTitle()); - - return ResponseEntity.status(HttpStatus.OK).body(conversationApiMapper.mapCompact(conversation)); + return null; } @ApiResponses( @@ -135,7 +147,7 @@ public ResponseEntity editConversation( @Operation(summary = "deletes a conversation") @DeleteMapping("/api/v1/conversation/{id}") public ResponseEntity deleteConversation(@PathVariable UUID id) - throws ConversationNotFoundException, UnAuthorizedException { + throws ConversationNotFoundException, UnauthorizedException { conversationService.getByID(id).orElseThrow(() -> new ConversationNotFoundException(id)); conversationService.delete(id); return ResponseEntity.status(HttpStatus.OK).body(null); @@ -161,8 +173,8 @@ public ResponseEntity handleConversationNotFoundException( return ResponseEntity.status(HttpStatus.NOT_FOUND).body(conversationNotFoundException.getMessage()); } - @ExceptionHandler(UnAuthorizedException.class) - public ResponseEntity handleUnAuthorized(UnAuthorizedException unAuthorizedException) { + @ExceptionHandler(UnauthorizedException.class) + public ResponseEntity handleUnAuthorized(UnauthorizedException unAuthorizedException) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unAuthorizedException.getMessage()); } } diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationRequest.java b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationRequest.java index 2bfe797..4ef9686 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationRequest.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationRequest.java @@ -1,5 +1,6 @@ package com.llm_service.llm_service.controller.conversation; +import com.llm_service.llm_service.constraint.ValidTextLength; import lombok.Builder; import lombok.NonNull; import lombok.Value; @@ -10,5 +11,6 @@ @Jacksonized public class ConversationRequest { @NonNull + @ValidTextLength String text; } diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java index e6f2e31..76d96a0 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java @@ -1,7 +1,8 @@ package com.llm_service.llm_service.controller.user; import com.llm_service.llm_service.dto.User; -import com.llm_service.llm_service.exception.UnAuthorizedException; +import com.llm_service.llm_service.dto.ValidationErrorResponse; +import com.llm_service.llm_service.exception.UnauthorizedException; import com.llm_service.llm_service.exception.user.UserAlreadyExistsException; import com.llm_service.llm_service.exception.user.UserNotFoundException; import com.llm_service.llm_service.exception.user.UsernameAlreadyExistsException; @@ -39,8 +40,8 @@ public UserController(AuthenticationService authenticationService, UserApiMapper }) @Operation(summary = "get the current user") @GetMapping("/api/v1/me") - public ResponseEntity register() throws UnAuthorizedException { - User user = authenticationService.getUser().orElseThrow(UnAuthorizedException::new); + public ResponseEntity register() throws UnauthorizedException { + User user = authenticationService.getUser().orElseThrow(UnauthorizedException::new); return ResponseEntity.status(HttpStatus.OK).body(userApiMapper.map(user)); } diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/user/ValidationErrorResponse.java b/backend/src/main/java/com/llm_service/llm_service/dto/ValidationErrorResponse.java similarity index 91% rename from backend/src/main/java/com/llm_service/llm_service/controller/user/ValidationErrorResponse.java rename to backend/src/main/java/com/llm_service/llm_service/dto/ValidationErrorResponse.java index aebfab7..3227703 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/user/ValidationErrorResponse.java +++ b/backend/src/main/java/com/llm_service/llm_service/dto/ValidationErrorResponse.java @@ -1,4 +1,4 @@ -package com.llm_service.llm_service.controller.user; +package com.llm_service.llm_service.dto; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/backend/src/main/java/com/llm_service/llm_service/exception/UnAuthorizedException.java b/backend/src/main/java/com/llm_service/llm_service/exception/UnAuthorizedException.java deleted file mode 100644 index 8fa08b4..0000000 --- a/backend/src/main/java/com/llm_service/llm_service/exception/UnAuthorizedException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.llm_service.llm_service.exception; - -public class UnAuthorizedException extends Exception { - public UnAuthorizedException() { - super("UnAuthorized"); - } -} diff --git a/backend/src/main/java/com/llm_service/llm_service/exception/UnauthorizedException.java b/backend/src/main/java/com/llm_service/llm_service/exception/UnauthorizedException.java new file mode 100644 index 0000000..9cab1ae --- /dev/null +++ b/backend/src/main/java/com/llm_service/llm_service/exception/UnauthorizedException.java @@ -0,0 +1,7 @@ +package com.llm_service.llm_service.exception; + +public class UnauthorizedException extends Exception { + public UnauthorizedException() { + super("UnAuthorized"); + } +} diff --git a/backend/src/main/java/com/llm_service/llm_service/service/ConversationService.java b/backend/src/main/java/com/llm_service/llm_service/service/ConversationService.java index e61795f..4b39cd0 100644 --- a/backend/src/main/java/com/llm_service/llm_service/service/ConversationService.java +++ b/backend/src/main/java/com/llm_service/llm_service/service/ConversationService.java @@ -3,7 +3,7 @@ import com.llm_service.llm_service.dto.Conversation; import com.llm_service.llm_service.dto.Discussion; import com.llm_service.llm_service.dto.User; -import com.llm_service.llm_service.exception.UnAuthorizedException; +import com.llm_service.llm_service.exception.UnauthorizedException; import com.llm_service.llm_service.persistance.entities.DiscussionRole; import com.llm_service.llm_service.persistance.repositories.conversation.ConversationPersistenceManager; import com.llm_service.llm_service.persistance.repositories.discussion.DiscussionPersistenceManager; @@ -24,43 +24,43 @@ public class ConversationService { private final DiscussionPersistenceManager discussionPersistenceManager; private final UserContext userContext; - public Conversation start() throws UnAuthorizedException { + public Conversation start() throws UnauthorizedException { Optional user = userContext.getUserFromContext(); if (user.isEmpty()) { - throw new UnAuthorizedException(); + throw new UnauthorizedException(); } Conversation conversation = Conversation.builder().discussions(null).build(); return conversationPersistenceManager.save(conversation, user.get()); } - public List getAll() throws UnAuthorizedException { + public List getAll() throws UnauthorizedException { Optional user = userContext.getUserFromContext(); if (user.isEmpty()) { - throw new UnAuthorizedException(); + throw new UnauthorizedException(); } return conversationPersistenceManager.findAll(user.get().getId()); } - public Optional getByID(UUID id) throws UnAuthorizedException { + public Optional getByID(UUID id) throws UnauthorizedException { Optional user = userContext.getUserFromContext(); if (user.isEmpty()) { - throw new UnAuthorizedException(); + throw new UnauthorizedException(); } return conversationPersistenceManager.findById(id, user.get().getId()); } // TODO optimize this fetching mechanism - public List askLlmQuestion(Conversation conversation, String text) throws UnAuthorizedException { + public List askLlmQuestion(Conversation conversation, String text) throws UnauthorizedException { Optional user = userContext.getUserFromContext(); if (user.isEmpty()) { - throw new UnAuthorizedException(); + throw new UnauthorizedException(); } Discussion discussionFromUserParam = @@ -106,11 +106,11 @@ public void deleteAll() { conversationPersistenceManager.deleteAll(); } - public Conversation editTitle(Conversation conversation, String title) throws UnAuthorizedException { + public Conversation editTitle(Conversation conversation, String title) throws UnauthorizedException { Optional user = userContext.getUserFromContext(); if (user.isEmpty()) { - throw new UnAuthorizedException(); + throw new UnauthorizedException(); } Conversation savedConversation = saveEditedTitle(conversation, title, user); From b2019eb83695548705b548a0c2548c63728c24e0 Mon Sep 17 00:00:00 2001 From: Yerish26 Date: Tue, 14 May 2024 00:23:58 +0400 Subject: [PATCH 3/4] minor fix in user controller --- .../llm_service/controller/user/UserController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java index 76d96a0..3b480e7 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java @@ -103,4 +103,9 @@ ResponseEntity handleUsernameNotFoundExceptions(UserNotFoundException us ResponseEntity handleAuthenticationException(AuthenticationException authenticationException) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(authenticationException.getMessage()); } + + @ExceptionHandler(UnauthorizedException.class) + public ResponseEntity handleUnAuthorized(UnauthorizedException unAuthorizedException) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unAuthorizedException.getMessage()); + } } From de162cd125317800f866d4f5f6797eec7706144b Mon Sep 17 00:00:00 2001 From: Yerish26 Date: Tue, 14 May 2024 00:27:47 +0400 Subject: [PATCH 4/4] minor fix in exception handler --- .../controller/conversation/ConversationController.java | 4 ++-- .../llm_service/controller/user/UserController.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java index 20328ed..20c9953 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/conversation/ConversationController.java @@ -174,7 +174,7 @@ public ResponseEntity handleConversationNotFoundException( } @ExceptionHandler(UnauthorizedException.class) - public ResponseEntity handleUnAuthorized(UnauthorizedException unAuthorizedException) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unAuthorizedException.getMessage()); + public ResponseEntity handleUnAuthorized(UnauthorizedException unauthorizedException) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unauthorizedException.getMessage()); } } diff --git a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java index 3b480e7..d578c6d 100644 --- a/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java +++ b/backend/src/main/java/com/llm_service/llm_service/controller/user/UserController.java @@ -105,7 +105,7 @@ ResponseEntity handleAuthenticationException(AuthenticationException aut } @ExceptionHandler(UnauthorizedException.class) - public ResponseEntity handleUnAuthorized(UnauthorizedException unAuthorizedException) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unAuthorizedException.getMessage()); + public ResponseEntity handleUnauthorized(UnauthorizedException unauthorizedException) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(unauthorizedException.getMessage()); } }