From 3d666be18be53eb92b179315e265110a2c95f2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diana=20Gul=C4=8D=C3=ADkov=C3=A1?= <xgulcik@fi.muni.cz> Date: Sun, 16 Apr 2023 23:24:38 +0200 Subject: [PATCH] small fixes --- .../pa165/common_library/dtos/RaceDto.java | 6 ++--- .../pa165/common_library/dtos/SeasonDto.java | 3 +-- .../exception/RestExceptionHandler.java | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/common_library/src/main/java/cz/muni/pa165/common_library/dtos/RaceDto.java b/common_library/src/main/java/cz/muni/pa165/common_library/dtos/RaceDto.java index 6bfc8104..aa6f565d 100644 --- a/common_library/src/main/java/cz/muni/pa165/common_library/dtos/RaceDto.java +++ b/common_library/src/main/java/cz/muni/pa165/common_library/dtos/RaceDto.java @@ -23,10 +23,10 @@ public class RaceDto { @Schema(description = "race information") private RaceDto.RaceInfo raceInfo; - @Schema(description = "driver one", example = "{1, 1, Charles Leclerc}") + @Schema(description = "driver one") private RaceDriverCarDto driverOne; - @Schema(description = "driver two", example = "{2, 2, Carlos Sainz}") + @Schema(description = "driver two") private RaceDriverCarDto driverTwo; /** @@ -39,7 +39,7 @@ public class RaceDto { public static class RaceInfo { @NotNull - @Schema(description = "race location", example = "Monaco") + @Schema(description = "race location", example = "MONACO") private Location location; @NotNull diff --git a/common_library/src/main/java/cz/muni/pa165/common_library/dtos/SeasonDto.java b/common_library/src/main/java/cz/muni/pa165/common_library/dtos/SeasonDto.java index f5ea5df1..bb6664b5 100644 --- a/common_library/src/main/java/cz/muni/pa165/common_library/dtos/SeasonDto.java +++ b/common_library/src/main/java/cz/muni/pa165/common_library/dtos/SeasonDto.java @@ -30,7 +30,6 @@ public class SeasonDto { private int year; @NotNull - @Schema(description = "season races", example = "[{1, STC Saudi Arabian GP Jeddah}," - + " {2, Rolex Australian GP Melbourne}]") + @Schema(description = "season races") List<RaceNameDto> races; } diff --git a/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java b/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java index 2fa79a30..bfe65b08 100644 --- a/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java +++ b/common_library/src/main/java/cz/muni/pa165/common_library/exception/RestExceptionHandler.java @@ -1,6 +1,7 @@ package cz.muni.pa165.common_library.exception; import jakarta.persistence.EntityNotFoundException; +import org.apache.hc.client5.http.HttpHostConnectException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -11,6 +12,8 @@ import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.servlet.NoHandlerFoundException; /** @@ -102,4 +105,28 @@ public class RestExceptionHandler { return new ResponseEntity<>( new ExError(message), new HttpHeaders(), HttpStatus.BAD_REQUEST); } + + @ExceptionHandler(HttpServerErrorException.class) + public ResponseEntity<ExError> handleServerException(HttpServerErrorException ex) { + return new ResponseEntity<>( + new ExError(ex.getMessage()), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(HttpServerErrorException.InternalServerError.class) + public ResponseEntity<ExError> handleServerException(HttpServerErrorException.InternalServerError ex) { + return new ResponseEntity<>( + new ExError(ex.getMessage()), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(HttpHostConnectException.class) + public ResponseEntity<ExError> handleServerException(HttpHostConnectException ex) { + var message = ""; + if (ex.getMessage().contains("8083")) { + message = "Failed to connect to the driver service"; + } else if (ex.getMessage().contains("8082")){ + message = "Failed to connect to the car service"; + } + return new ResponseEntity<>( + new ExError(message), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR); + } } -- GitLab