-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from TTG-Club/feat/transfer-nuxt-backend
Перенос бэка с Nuxt
- Loading branch information
Showing
48 changed files
with
1,496 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
src/main/java/club/ttg/dnd5/controller/MenuApiController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/java/club/ttg/dnd5/controller/engine/ErrorHandlerControllerAdvice.java
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
src/main/java/club/ttg/dnd5/controller/engine/ExceptionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package club.ttg.dnd5.controller.engine; | ||
|
||
import club.ttg.dnd5.dto.ErrorResponseDto; | ||
import club.ttg.dnd5.exception.ApiException; | ||
import club.ttg.dnd5.exception.EntityExistException; | ||
import club.ttg.dnd5.exception.EntityNotFoundException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.authorization.AuthorizationDeniedException; | ||
import org.springframework.web.bind.MissingServletRequestParameterException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.multipart.MaxUploadSizeExceededException; | ||
import org.springframework.web.servlet.NoHandlerFoundException; | ||
|
||
import java.io.IOException; | ||
|
||
@Log4j2 | ||
@ControllerAdvice | ||
@RequiredArgsConstructor | ||
public class ExceptionController { | ||
@Value("${spring.servlet.multipart.max-file-size}") | ||
private String MAX_FILE_SIZE; | ||
|
||
@ExceptionHandler(ApiException.class) | ||
public ResponseEntity<ErrorResponseDto> handleApiException(ApiException ex, HttpServletRequest request, HttpServletResponse response) { | ||
log.error(ExceptionUtils.getStackTrace(ex)); | ||
|
||
return convertToResponseEntity(ex.getStatus(), ex.getMessage()); | ||
} | ||
|
||
@ExceptionHandler({SecurityException.class, AuthorizationDeniedException.class}) | ||
public ResponseEntity<ErrorResponseDto> handleSecurityException() { | ||
return convertToResponseEntity(HttpStatus.FORBIDDEN, "Доступ запрещен"); | ||
} | ||
|
||
@ExceptionHandler(MissingServletRequestParameterException.class) | ||
public ResponseEntity<ErrorResponseDto> handleRequestParamException(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response) { | ||
String message = String.format("Отсутствует необходимый параметр \"%s\"", ex.getParameterName()); | ||
|
||
return convertToResponseEntity(HttpStatus.BAD_REQUEST, message); | ||
} | ||
|
||
@ExceptionHandler(MaxUploadSizeExceededException.class) | ||
public ResponseEntity<ErrorResponseDto> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException ex, HttpServletRequest request, HttpServletResponse response) { | ||
String message = String.format("Максимальный размер загружаемых файлов – %s", MAX_FILE_SIZE); | ||
|
||
return convertToResponseEntity(HttpStatus.BAD_REQUEST, message); | ||
} | ||
|
||
@ExceptionHandler({NoHandlerFoundException.class, IOException.class, Exception.class}) | ||
public ResponseEntity<ErrorResponseDto> handleOtherExceptions(Exception ex, HttpServletRequest request, HttpServletResponse response) { | ||
log.error(ExceptionUtils.getStackTrace(ex)); | ||
|
||
return convertToResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(EntityNotFoundException.class) | ||
public ResponseEntity<ErrorResponseDto> handleEntityNotFound(Exception exception) { | ||
return convertToResponseEntity(HttpStatus.NOT_FOUND, exception.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(EntityExistException.class) | ||
public ResponseEntity<ErrorResponseDto> handleHandleEntityExistException(Exception exception) { | ||
return convertToResponseEntity(HttpStatus.BAD_REQUEST, exception.getMessage()); | ||
} | ||
|
||
private ResponseEntity<ErrorResponseDto> convertToResponseEntity(HttpStatus status, String message) { | ||
return ResponseEntity.status(status).body(new ErrorResponseDto(status, message)); | ||
} | ||
} |
Oops, something went wrong.