diff --git a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java index 92b9f8ef..b26a65cf 100644 --- a/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java +++ b/api-gateway/src/main/java/com/jmsoftware/maf/apigateway/universal/handler/GlobalExceptionHandler.java @@ -44,7 +44,8 @@ public Mono handle(ServerWebExchange exchange, Throwable ex) { if (response.isCommitted()) { return Mono.error(ex); } - // Set HTTP header + // Set HTTP header, major browsers like Chrome now comply with the specification and interpret correctly + // UTF-8 special characters without requiring a charset=UTF-8 parameter. response.getHeaders().setContentType(MediaType.APPLICATION_JSON); return response.writeWith(Mono.fromSupplier(() -> { DataBufferFactory bufferFactory = response.bufferFactory(); @@ -71,7 +72,8 @@ private ResponseBodyBean setResponseBody(ServerHttpResponse response, Throwab return ResponseBodyBean.ofStatus(((ResponseStatusException) ex).getStatus()); } else if (ex instanceof HystrixRuntimeException) { response.setStatusCode(HttpStatus.SERVICE_UNAVAILABLE); - return ResponseBodyBean.ofStatus(HttpStatus.SERVICE_UNAVAILABLE, ex.getMessage()); + return ResponseBodyBean.ofStatus(HttpStatus.SERVICE_UNAVAILABLE, + String.format("%s %s", ex.getMessage(), ex.getCause().getMessage())); } response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); return ResponseBodyBean.ofStatus(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage()); diff --git a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverreactivespringbootstarter/util/ResponseUtil.java b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverreactivespringbootstarter/util/ResponseUtil.java index 8041f787..b97c68b5 100644 --- a/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverreactivespringbootstarter/util/ResponseUtil.java +++ b/reactive-spring-boot-starter/src/main/java/com/jmsoftware/maf/muscleandfitnessserverreactivespringbootstarter/util/ResponseUtil.java @@ -8,6 +8,7 @@ import lombok.val; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @@ -33,7 +34,9 @@ public static Mono renderJson(@NonNull ServerWebExchange exchange, @NonNul exchange.getResponse().setStatusCode(httpStatus); val response = exchange.getResponse(); response.setStatusCode(httpStatus); - response.getHeaders().set("Content-Type", "application/json;charset=UTF-8"); + // Set HTTP header, major browsers like Chrome now comply with the specification and interpret correctly + // UTF-8 special characters without requiring a charset=UTF-8 parameter. + response.getHeaders().setContentType(MediaType.APPLICATION_JSON); return response.writeWith(Mono.fromSupplier(() -> { DataBufferFactory bufferFactory = response.bufferFactory(); final var responseBody = ResponseBodyBean.ofStatus(httpStatus, data);