Skip to content

Commit 1bb56b9

Browse files
committed
Use NotFoundException for handling absent pages.
No functional changes.
1 parent f291170 commit 1bb56b9

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/main/java/ru/mystamps/web/controller/ImageController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void getImage(@PathVariable("id") Integer id, HttpServletResponse respons
4747

4848
Image image = imageService.findById(id);
4949
if (image == null) {
50-
response.sendError(HttpServletResponse.SC_NOT_FOUND);
51-
return;
50+
throw new NotFoundException();
5251
}
5352

5453
// TODO: set content disposition
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2009-2012 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
19+
package ru.mystamps.web.controller;
20+
21+
import org.springframework.http.HttpStatus;
22+
import org.springframework.web.bind.annotation.ResponseStatus;
23+
24+
@ResponseStatus(HttpStatus.NOT_FOUND)
25+
public class NotFoundException extends RuntimeException {
26+
}
27+

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222

2323
import javax.inject.Inject;
24-
import javax.servlet.http.HttpServletResponse;
2524
import javax.validation.groups.Default;
2625

2726
import java.util.Calendar;
@@ -124,15 +123,11 @@ public String processInput(
124123
}
125124

126125
@RequestMapping(value = Url.INFO_SERIES_PAGE, method = RequestMethod.GET)
127-
public String showInfo(
128-
@PathVariable("id") Integer id,
129-
Model model,
130-
HttpServletResponse response) throws IOException {
126+
public String showInfo(@PathVariable("id") Integer id, Model model) throws IOException {
131127

132128
Series series = seriesService.findById(id);
133129
if (series == null) {
134-
response.sendError(HttpServletResponse.SC_NOT_FOUND);
135-
return null;
130+
throw new NotFoundException();
136131
}
137132

138133
model.addAttribute("series", series);

0 commit comments

Comments
 (0)