Skip to content

Commit ef52124

Browse files
committed
fix exception bug in UrlsController.create()
1 parent 88f22c2 commit ef52124

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/src/main/java/hexlet/code/controller/UrlsController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.URI;
1414
import java.net.URISyntaxException;
1515
import java.sql.SQLException;
16+
import java.util.Objects;
1617

1718
import static io.javalin.rendering.template.TemplateUtil.model;
1819

@@ -47,7 +48,10 @@ public static void show(Context ctx) throws SQLException {
4748

4849
public static void create(Context ctx) throws SQLException {
4950

50-
var inputUrl = ctx.formParamAsClass("url", String.class).getOrThrow(NotFoundResponse::new);
51+
var inputUrl = ctx.formParamAsClass("url", String.class)
52+
.check(Objects::nonNull, "Url not found in form")
53+
.getOrThrow(NotFoundResponse::new);
54+
5155
URI parsedUrl;
5256
try {
5357
parsedUrl = new URI(inputUrl);

0 commit comments

Comments
 (0)