Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message for invalid locale #6776

Merged
merged 5 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ValidationConstants {
public static final int MAX_AMOUNT_OF_TAGS = 3;
public static final int PLACE_NAME_MAX_LENGTH = 30;
public static final int MAX_EVENT_DATES_AMOUNT = 7;
public static final String LANGUAGE_VALIDATION_EXCEPTION_MESSAGE = "Select correct language: 'en' or 'ua'";
public static final String LOCALE_PART_ERROR_MESSAGE = "Locale part";

private ValidationConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,37 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import greencity.constant.AppConstant;
import greencity.constant.ErrorMessage;
import greencity.exception.exceptions.*;
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import greencity.constant.ValidationConstants;
import greencity.exception.exceptions.BadCategoryRequestException;
import greencity.exception.exceptions.BadPlaceRequestException;
import greencity.exception.exceptions.BadRefreshTokenException;
import greencity.exception.exceptions.BadRequestException;
import greencity.exception.exceptions.BadSocialNetworkLinksException;
import greencity.exception.exceptions.EmailNotVerified;
import greencity.exception.exceptions.EventDtoValidationException;
import greencity.exception.exceptions.InvalidStatusException;
import greencity.exception.exceptions.InvalidURLException;
import greencity.exception.exceptions.NotCurrentUserException;
import greencity.exception.exceptions.NotDeleteLastHabit;
import greencity.exception.exceptions.NotDeletedException;
import greencity.exception.exceptions.NotFoundException;
import greencity.exception.exceptions.NotSavedException;
import greencity.exception.exceptions.NotUpdatedException;
import greencity.exception.exceptions.ShoppingListItemNotFoundException;
import greencity.exception.exceptions.TagNotFoundException;
import greencity.exception.exceptions.UnsupportedSortException;
import greencity.exception.exceptions.UserAlreadyHasEnrolledHabitAssign;
import greencity.exception.exceptions.UserAlreadyHasHabitAssignedException;
import greencity.exception.exceptions.UserAlreadyRegisteredException;
import greencity.exception.exceptions.UserHasNoAvailableHabitTranslationException;
import greencity.exception.exceptions.UserHasNoFriendWithIdException;
import greencity.exception.exceptions.UserHasNoPermissionToAccessException;
import greencity.exception.exceptions.UserHasNoShoppingListItemsException;
import greencity.exception.exceptions.UserHasReachedOutOfEnrollRange;
import greencity.exception.exceptions.UserShoppingListItemNotSavedException;
import greencity.exception.exceptions.UserShoppingListItemStatusNotUpdatedException;
import greencity.exception.exceptions.WrongEmailOrPasswordException;
import greencity.exception.exceptions.WrongIdException;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -32,6 +54,15 @@
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Custom exception handler.
*
Expand Down Expand Up @@ -189,6 +220,9 @@ public final ResponseEntity<Object> handleConstraintViolationException(Constrain
public ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException ex, WebRequest request) {
log.info(ex.getMessage());
ExceptionResponse exceptionResponse = new ExceptionResponse(getErrorAttributes(request));
if (ex.getMessage().startsWith(ValidationConstants.LOCALE_PART_ERROR_MESSAGE)) {
exceptionResponse.setMessage(ValidationConstants.LANGUAGE_VALIDATION_EXCEPTION_MESSAGE);
}
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exceptionResponse);
}

Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
<net.java.dev.jna.version>4.5.2</net.java.dev.jna.version>
</properties>

<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.exclusions>**/CustomExceptionHandler.java</sonar.exclusions>
</properties>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand Down
Loading