org.zodiac.scaff.crud.web.R2dbcErrorControllerAdvice Maven / Gradle / Ivy
The newest version!
package org.zodiac.scaff.crud.web;
import io.r2dbc.spi.R2dbcDataIntegrityViolationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.zodiac.reactor.util.SpringLocaleUtil;
import reactor.core.publisher.Mono;
@RestControllerAdvice
public class R2dbcErrorControllerAdvice {
protected final Logger log = LoggerFactory.getLogger(getClass());
public R2dbcErrorControllerAdvice() {
super();
}
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Mono> handleException(R2dbcDataIntegrityViolationException e) {
String code;
if (e.getMessage().contains("Duplicate")) {
code = "error.duplicate_data";
} else {
code = "error.data_error";
log.warn(e.getMessage(), e);
}
return SpringLocaleUtil
.resolveMessageReactive(code)
.map(msg -> ResponseMessage.error(400, code, msg));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy