From 4d08bf0d2744b397c93a563208d784db30db4ab9 Mon Sep 17 00:00:00 2001 From: Mikhail Trofimov Date: Fri, 27 Jun 2025 10:16:24 +0300 Subject: [PATCH] Changed error response encoding --- .../config/rest/GlobalExceptionHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/nbch/credit_tracker/config/rest/GlobalExceptionHandler.java b/src/main/java/ru/nbch/credit_tracker/config/rest/GlobalExceptionHandler.java index 7d7863d..3ce661b 100644 --- a/src/main/java/ru/nbch/credit_tracker/config/rest/GlobalExceptionHandler.java +++ b/src/main/java/ru/nbch/credit_tracker/config/rest/GlobalExceptionHandler.java @@ -1,5 +1,7 @@ package ru.nbch.credit_tracker.config.rest; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -7,15 +9,19 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import ru.nbch.credit_tracker.entities.response.errors.CommonError; import ru.nbch.credit_tracker.exceptions.SignalErrorException; +import java.nio.charset.Charset; + @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(value = SignalErrorException.class, produces = MediaType.APPLICATION_XML_VALUE) public ResponseEntity handleInvalidUser(SignalErrorException ex) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(new MediaType("application", "xml", Charset.forName("windows-1251"))); if (ex.isUserError()) { - return ResponseEntity.badRequest().body(ex.getError()); + return new ResponseEntity<>(ex.getError(), headers, HttpStatus.BAD_REQUEST); } else { - return ResponseEntity.internalServerError().body(ex.getError()); + return new ResponseEntity<>(ex.getError(), headers, HttpStatus.INTERNAL_SERVER_ERROR); } } }