aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/www/controllers')
-rw-r--r--src/main/java/com/juick/www/controllers/Site.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java
index 1e308f6a..ed8f951e 100644
--- a/src/main/java/com/juick/www/controllers/Site.java
+++ b/src/main/java/com/juick/www/controllers/Site.java
@@ -30,16 +30,21 @@ import com.juick.util.MessageUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.text.StringEscapeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
+import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
@@ -59,6 +64,7 @@ import java.util.stream.Collectors;
*/
@Controller
public class Site {
+ private static final Logger logger = LoggerFactory.getLogger("Site");
@Inject
private UserService userService;
@Inject
@@ -594,4 +600,11 @@ public class Site {
public ResponseEntity<String> notFoundAction() {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
+
+ @ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
+ public ResponseEntity<String> invalidMediaType(final HttpMediaTypeNotAcceptableException exception,
+ final NativeWebRequest request) {
+ logger.info("Invalid media type {}, url: {}", request.getHeaderValues("Content-Type"), ServletUriComponentsBuilder.fromCurrentRequestUri());
+ return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+ }
}