Changed error response encoding
This commit is contained in:
parent
a1fb717e10
commit
4d08bf0d27
1 changed files with 8 additions and 2 deletions
|
|
@ -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<CommonError> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue