diff --git a/src/main/java/org/ays/auth/exception/AysAdminRegistrationApplicationInCompleteException.java b/src/main/java/org/ays/auth/exception/AysAdminRegistrationApplicationInCompleteException.java index e3c2ab0a..e2241f63 100644 --- a/src/main/java/org/ays/auth/exception/AysAdminRegistrationApplicationInCompleteException.java +++ b/src/main/java/org/ays/auth/exception/AysAdminRegistrationApplicationInCompleteException.java @@ -1,18 +1,18 @@ package org.ays.auth.exception; import org.ays.auth.model.enums.AdminRegistrationApplicationStatus; -import org.ays.common.exception.AysBadRequestException; +import org.ays.common.exception.AysConflictException; import java.io.Serial; /** * Exception indicating that an admin registration application is not completed to be rejected. - * This exception is a subclass of {@link AysBadRequestException}, which is typically used to indicate that an entity or + * This exception is a subclass of {@link AysConflictException}, which is typically used to indicate that an entity or * resource was incorrectly used during the process. * Typically, this exception is thrown when a rejection operation is performed on an admin register application * entity to an incomplete application, where its status is not set to 'COMPLETE'. */ -public final class AysAdminRegistrationApplicationInCompleteException extends AysBadRequestException { +public final class AysAdminRegistrationApplicationInCompleteException extends AysConflictException { /** * Unique identifier for serialization. diff --git a/src/main/java/org/ays/common/exception/AysBadRequestException.java b/src/main/java/org/ays/common/exception/AysBadRequestException.java deleted file mode 100644 index db798168..00000000 --- a/src/main/java/org/ays/common/exception/AysBadRequestException.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.ays.common.exception; - -import java.io.Serial; - -/** - * Exception to be thrown when a bad request is made to the application. - */ -public abstract class AysBadRequestException extends RuntimeException { - - /** - * Unique identifier for serialization. - */ - @Serial - private static final long serialVersionUID = 6127207732429966431L; - - /** - * Constructs a new {@link AysBadRequestException} with the specified detail message. - * - * @param message the detail message. - */ - protected AysBadRequestException(final String message) { - super(message); - } - -} diff --git a/src/main/java/org/ays/common/exception/handler/GlobalExceptionHandler.java b/src/main/java/org/ays/common/exception/handler/GlobalExceptionHandler.java index 3710f8e0..10f14490 100644 --- a/src/main/java/org/ays/common/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/org/ays/common/exception/handler/GlobalExceptionHandler.java @@ -4,7 +4,6 @@ import jakarta.validation.ConstraintViolationException; import lombok.extern.slf4j.Slf4j; import org.ays.common.exception.AysAuthException; -import org.ays.common.exception.AysBadRequestException; import org.ays.common.exception.AysConflictException; import org.ays.common.exception.AysForbiddenException; import org.ays.common.exception.AysNotExistException; @@ -91,17 +90,6 @@ AysErrorResponse handleNotExistError(final AysNotExistException exception) { .build(); } - @ExceptionHandler(AysBadRequestException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - AysErrorResponse handleBadRequestError(final AysBadRequestException exception) { - log.error(exception.getMessage(), exception); - - return AysErrorResponse.builder() - .header(AysErrorResponse.Header.BAD_REQUEST.getName()) - .message(exception.getMessage()) - .build(); - } - @ExceptionHandler(AysConflictException.class) @ResponseStatus(HttpStatus.CONFLICT) AysErrorResponse handleAlreadyExistError(final AysConflictException exception) { diff --git a/src/main/java/org/ays/common/model/response/AysErrorResponse.java b/src/main/java/org/ays/common/model/response/AysErrorResponse.java index 0f84f3e0..f0f3b2ea 100644 --- a/src/main/java/org/ays/common/model/response/AysErrorResponse.java +++ b/src/main/java/org/ays/common/model/response/AysErrorResponse.java @@ -118,10 +118,6 @@ public enum Header { * PROCESS_ERROR header. */ PROCESS_ERROR("PROCESS ERROR"), - /** - * BAD_REQUEST header. - */ - BAD_REQUEST("BAD REQUEST"), /** * AUTH_ERROR header. */ diff --git a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java index 789c0959..f5dacd3a 100644 --- a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationEndToEndTest.java @@ -555,11 +555,11 @@ void givenValidAdminRegistrationApplicationId_whenApproveAdminRegistrationApplic MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders .post(endpoint, superAdminToken.getAccessToken()); - AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST; + AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.ALREADY_EXIST; aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse) .andExpect(AysMockResultMatchersBuilders.status() - .isBadRequest()) + .isConflict()) .andExpect(AysMockResultMatchersBuilders.response() .doesNotExist()); } @@ -779,11 +779,11 @@ void givenValidAdminRegistrationApplicationRejectRequest_whenRejectAdminRegistra MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders .post(endpoint, superAdminToken.getAccessToken(), rejectRequest); - AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.BAD_REQUEST; + AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.ALREADY_EXIST; aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse) .andExpect(AysMockResultMatchersBuilders.status() - .isBadRequest()) + .isConflict()) .andExpect(AysMockResultMatchersBuilders.response() .doesNotExist()); } diff --git a/src/test/java/org/ays/common/exception/handler/GlobalExceptionHandlerTest.java b/src/test/java/org/ays/common/exception/handler/GlobalExceptionHandlerTest.java index d10f1753..5a6c445f 100644 --- a/src/test/java/org/ays/common/exception/handler/GlobalExceptionHandlerTest.java +++ b/src/test/java/org/ays/common/exception/handler/GlobalExceptionHandlerTest.java @@ -6,7 +6,6 @@ import jakarta.validation.constraints.NotNull; import org.ays.AysRestControllerTest; import org.ays.common.exception.AysAuthException; -import org.ays.common.exception.AysBadRequestException; import org.ays.common.exception.AysForbiddenException; import org.ays.common.exception.AysNotExistException; import org.ays.common.exception.AysProcessException; @@ -340,31 +339,6 @@ void givenInvalidJsonFormat_whenThrowHttpMessageNotReadableException_thenReturnA this.checkAysError(mockErrorResponse, errorResponse); } - @Test - void givenInvalidStatus_whenThrowAysInvalidStatusException_thenReturnAysErrorWithReturnAysError() { - - // Given - AysBadRequestException mockException = new AysBadRequestException("Bad request") { - @Serial - private static final long serialVersionUID = 1L; - - @Override - public String getMessage() { - return "Bad request"; - } - }; - - // When - AysErrorResponse mockErrorResponse = AysErrorResponse.builder() - .header(AysErrorResponse.Header.BAD_REQUEST.getName()) - .message(mockException.getMessage()) - .build(); - - // Then - AysErrorResponse errorResponse = globalExceptionHandler.handleBadRequestError(mockException); - this.checkAysError(mockErrorResponse, errorResponse); - } - private void checkAysError(AysErrorResponse mockErrorResponse, AysErrorResponse errorResponse) { Assertions.assertNotNull(errorResponse.getTime()); Assertions.assertNotNull(errorResponse.getCode()); diff --git a/src/test/java/org/ays/common/model/response/AysErrorResponseBuilder.java b/src/test/java/org/ays/common/model/response/AysErrorResponseBuilder.java index 50f09a99..64605d32 100644 --- a/src/test/java/org/ays/common/model/response/AysErrorResponseBuilder.java +++ b/src/test/java/org/ays/common/model/response/AysErrorResponseBuilder.java @@ -18,10 +18,6 @@ public class AysErrorResponseBuilder { .header(AysErrorResponse.Header.ALREADY_EXIST.getName()) .isSuccess(false).build(); - public static final AysErrorResponse BAD_REQUEST = AysErrorResponse.builder() - .header(AysErrorResponse.Header.BAD_REQUEST.getName()) - .isSuccess(false).build(); - public static final AysErrorResponse NOT_FOUND = AysErrorResponse.builder() .header(AysErrorResponse.Header.NOT_FOUND.getName()) .isSuccess(false).build();