aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-10-30 05:08:45 +0300
committerGravatar Vitaly Takmazov2021-10-30 05:16:54 +0300
commitcedf00d682ef0b62e291f9fec9946162bcdc098e (patch)
tree06f063cf601646b5fa8f90829992c0a24ade3137 /src
parentb510c139c7b0931c1e17aeaf13b92488f4da1fd1 (diff)
Handle wrong RSS path correctly
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/www/rss/Feeds.java10
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java2
2 files changed, 11 insertions, 1 deletions
diff --git a/src/main/java/com/juick/www/rss/Feeds.java b/src/main/java/com/juick/www/rss/Feeds.java
index 4423b263..8111f2df 100644
--- a/src/main/java/com/juick/www/rss/Feeds.java
+++ b/src/main/java/com/juick/www/rss/Feeds.java
@@ -22,7 +22,12 @@ import com.juick.util.HttpNotFoundException;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
import com.juick.service.security.annotation.Visitor;
+
+import org.springframework.core.convert.ConversionFailedException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+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;
@@ -79,4 +84,9 @@ public class Feeds {
modelAndView.addObject("messages", messagesService.getLastReplies(hours));
return modelAndView;
}
+ // wrong feed type
+ @ExceptionHandler(ConversionFailedException.class)
+ public ResponseEntity<String> notFoundAction() {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 14517a60..5bb10ae9 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2361,7 +2361,7 @@ public class ServerTests {
+ "q=0.8,application/signed-exchange;v=b3"))
.andExpect(status().isOk()).andExpect(content().contentType("application/rss+xml;charset=UTF-8"));
mockMvc.perform(get("/rss/ugnich/feed").accept(MediaType.TEXT_XML)).andExpect(status().isOk());
- mockMvc.perform(get("/rss/ugnich/diary").accept(MediaType.TEXT_XML)).andExpect(status().isBadRequest());
+ mockMvc.perform(get("/rss/ugnich/diary").accept(MediaType.TEXT_XML)).andExpect(status().isNotFound());
}
@Test