diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalExceptionHandler.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalExceptionHandler.java index f0fadd8987..05871cfa8b 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalExceptionHandler.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -16,6 +17,8 @@ import java.util.HashMap; import java.util.Map; +import static org.springframework.http.HttpStatus.NOT_FOUND; + /** * Created by IntelliJ IDEA. @@ -129,4 +132,13 @@ public ResponseEntity handleForbiddenAccessException(ForbiddenAcc .body(new HttpErrorInfo(HttpStatus.FORBIDDEN.value(),ex.getMessage())); } + //I have no idea why but this method kills docker and specifically + //the api gateway as a service crashes on docker if you have this uncommented +// @ExceptionHandler(value = NotFoundException.class) +// public ResponseEntity handleNotFoundException(NotFoundException ex) { +// return ResponseEntity.status(NOT_FOUND) +// .body(new HttpErrorInfo(NOT_FOUND.value(),ex.getMessage())); +// +// } + } \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalServletExceptionHandler.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalServletExceptionHandler.java index d66e2f449d..44c369e5ca 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalServletExceptionHandler.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/config/GlobalServletExceptionHandler.java @@ -48,7 +48,11 @@ else if(exClass.equals(NullPointerException.class)){ } else if(exClass.equals(ForbiddenAccessException.class)){ status = HttpStatus.FORBIDDEN; - } // Handle any other exception types here + + } + else if(exClass.equals(NotFoundException.class)){ + status = HttpStatus.NOT_FOUND; + }// Handle any other exception types here else { log.error("Exception not handled: {}", exClass.getSimpleName()); status = HttpStatus.UNPROCESSABLE_ENTITY; diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java index c82ab3fc3d..ed9029d3a3 100755 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/CustomersServiceClient.java @@ -4,8 +4,11 @@ import com.petclinic.bffapigateway.dtos.CustomerDTOs.OwnerResponseDTO; import com.petclinic.bffapigateway.dtos.Pets.*; import com.petclinic.bffapigateway.dtos.Vets.PhotoDetails; +import com.petclinic.bffapigateway.exceptions.NotFoundException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestParam; @@ -41,6 +44,16 @@ public Mono getOwner(final String ownerId) { return webClientBuilder.build().get() .uri(customersServiceUrl + "/owners/" + ownerId) .retrieve() + .onStatus(HttpStatusCode::is4xxClientError, error->{ + HttpStatusCode statusCode = error.statusCode(); + + if (statusCode.equals(HttpStatus.NOT_FOUND)) + return Mono.error(new NotFoundException("Course id not found:" + ownerId)); + return Mono.error(new IllegalArgumentException("Something went wrong(owner Client)")); + }) + .onStatus(HttpStatusCode::is5xxServerError, error-> { + return Mono.error(new IllegalArgumentException("Something went wrong(owner Client")); + }) .bodyToMono(OwnerResponseDTO.class); } diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/exceptions/NotFoundException.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/exceptions/NotFoundException.java new file mode 100644 index 0000000000..a48df23d50 --- /dev/null +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/exceptions/NotFoundException.java @@ -0,0 +1,12 @@ +package com.petclinic.bffapigateway.exceptions; + +public class NotFoundException extends RuntimeException{ + + public NotFoundException() {} + + public NotFoundException(String message) { super(message); } + + public NotFoundException(Throwable cause) { super(cause); } + + public NotFoundException(String message, Throwable cause) { super(message, cause); } +} \ No newline at end of file diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java index 1c32f41149..d172d5db05 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/presentationlayer/BFFApiGatewayController.java @@ -703,12 +703,6 @@ public Mono> updateOwner( } - - - - - - @SecuredEndpoint(allowedRoles = {Roles.ADMIN}) @DeleteMapping(value = "owners/{ownerId}") public Mono> deleteOwner(@PathVariable String ownerId){ diff --git a/api-gateway/src/main/resources/static/scripts/fragments/nav.html b/api-gateway/src/main/resources/static/scripts/fragments/nav.html index bed3466466..12439889d9 100644 --- a/api-gateway/src/main/resources/static/scripts/fragments/nav.html +++ b/api-gateway/src/main/resources/static/scripts/fragments/nav.html @@ -1,4 +1,16 @@ diff --git a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.js b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.js index 4b90325713..b69a0a090a 100644 --- a/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.js +++ b/api-gateway/src/main/resources/static/scripts/owner-details/owner-details.js @@ -15,7 +15,6 @@ angular.module('ownerDetails', ['ui.router']) // params: {ownerId: null, petId: null}, // template: '' // } - }]); diff --git a/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.controller.js b/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.controller.js index 865d7c164e..c689d672f4 100755 --- a/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.controller.js +++ b/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.controller.js @@ -52,7 +52,7 @@ angular.module('vetList') $http.get('api/gateway/vets/' + vet.vetId + "/ratings/average").then(function (resp) { console.log(resp.data); vet.showRating = true; - vet.rating = parseFloat(resp.data.toFixed(1)); + vet.rating = parseFloat(resp.data).toFixed(1); }); } @@ -60,7 +60,7 @@ angular.module('vetList') $http.get('api/gateway/vets/topVets').then(function (resp) { console.log(resp.data); vet.showRating=true; - vet.rating = parseFloat(resp.data.toFixed(1)); + vet.rating = parseFloat(resp.data).toFixed(1); }); diff --git a/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.template.html b/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.template.html index a35c4832b9..2d03c59bbb 100644 --- a/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.template.html +++ b/api-gateway/src/main/resources/static/scripts/vet-list/vet-list.template.html @@ -20,6 +20,10 @@

Veterinarians

+ + + +
@@ -41,7 +45,7 @@

Veterinarians

Specialties Average Rating Number of Ratings - Delete + Delete @@ -56,14 +60,9 @@

Veterinarians

{{specialty.name + ' '}} {{vet.rating}} {{vet.count}} - Delete Vet + Delete Vet - - - - -