From 14940bf9bf63b1ca8d7d09fde37be52c9ae94ca8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 11 Jan 2017 15:00:58 +0300 Subject: juick-www: handle UserThread exceptions --- .../main/java/com/juick/www/controllers/UserThread.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'juick-www') diff --git a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java index 4020e149..5765e02d 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/UserThread.java +++ b/juick-www/src/main/java/com/juick/www/controllers/UserThread.java @@ -19,12 +19,16 @@ package com.juick.www.controllers; import com.juick.Message; import com.juick.server.helpers.TagStats; +import com.juick.server.util.HttpNotFoundException; import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.MessageUtils; import com.juick.www.WebApp; +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.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -68,6 +72,10 @@ public class UserThread { com.juick.Message msg = messagesService.getMessage(mid); + if (msg == null) { + throw new HttpNotFoundException(); + } + boolean listview = false; String paramView = request.getParameter("view"); if (paramView != null) { @@ -108,6 +116,12 @@ public class UserThread { } } + // when message id is not fit to int + @ExceptionHandler(NumberFormatException.class) + public ResponseEntity notfound() { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + public com.juick.Message printMessage(PrintWriter out, com.juick.Message msg, com.juick.User visitor) { msg.VisitorCanComment = visitor.getUid() > 0; -- cgit v1.2.3