From 96499ca1e3c09855559d55852e090aedb803fc27 Mon Sep 17 00:00:00 2001 From: JFronny Date: Sat, 22 Oct 2022 20:30:45 +0200 Subject: [PATCH] [http] Throw FileNotFoundException on 404 --- src/main/java/io/gitlab/jfronny/commons/HttpUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/gitlab/jfronny/commons/HttpUtils.java b/src/main/java/io/gitlab/jfronny/commons/HttpUtils.java index 0f794fe..7f18ca4 100644 --- a/src/main/java/io/gitlab/jfronny/commons/HttpUtils.java +++ b/src/main/java/io/gitlab/jfronny/commons/HttpUtils.java @@ -2,9 +2,7 @@ package io.gitlab.jfronny.commons; import io.gitlab.jfronny.commons.serialize.Serializer; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.lang.reflect.Type; import java.net.*; import java.net.http.HttpClient; @@ -160,6 +158,7 @@ public class HttpUtils { } return _send(accept, responseBodyHandler); } + if (res.statusCode() == 404) throw new FileNotFoundException("Didn't find anything under that url (URL=" + url + ")"); throw new IOException("Unexpected return method: " + res.statusCode() + " (URL=" + url + ")"); } @@ -216,4 +215,8 @@ public class HttpUtils { public static Request delete(String url) throws URISyntaxException { return new Request(Method.DELETE, url); } + + public static void main(String[] args) throws URISyntaxException, IOException { + get("https://frohnmeyer-wds.de/doesnt_exxist").send(); + } }