mirror of https://github.com/halo-dev/halo
Handle HttpMediaTypeNotAcceptableException with 406 status
parent
4cd77ed829
commit
0353c92995
|
@ -3,7 +3,6 @@ package run.halo.app.config;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import freemarker.template.TemplateExceptionHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jackson.JsonComponentModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -44,8 +43,11 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
|||
|
||||
private static final String FILE_PROTOCOL = "file:///";
|
||||
|
||||
@Autowired
|
||||
private HaloProperties haloProperties;
|
||||
private final HaloProperties haloProperties;
|
||||
|
||||
public WebMvcAutoConfiguration(HaloProperties haloProperties) {
|
||||
this.haloProperties = haloProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package run.halo.app.web.controller.base;
|
||||
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
import run.halo.app.exception.HaloException;
|
||||
import run.halo.app.model.support.BaseResponse;
|
||||
import run.halo.app.utils.ExceptionUtils;
|
||||
|
@ -82,6 +83,14 @@ public class ControllerExceptionHandler {
|
|||
return baseResponse;
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
|
||||
@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
|
||||
public BaseResponse handleHttpMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException e) {
|
||||
BaseResponse<?> baseResponse = handleBaseException(e);
|
||||
baseResponse.setStatus(HttpStatus.NOT_ACCEPTABLE.value());
|
||||
return baseResponse;
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public BaseResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
||||
|
|
Loading…
Reference in New Issue