From 5afbcd9ffe071afb16bb9530d5284905206ede29 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 26 Jul 2023 23:11:19 +0200 Subject: [PATCH 1/3] task throw an exception when response isn't a 200 code --- buildSrc/src/main/java/fr/altarik/ReportDiscord.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java index c61d69d..d5c49b5 100644 --- a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java +++ b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java @@ -5,6 +5,7 @@ import org.gradle.api.DefaultTask; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; +import org.gradle.internal.impldep.org.apache.http.client.HttpResponseException; import java.io.IOException; @@ -41,6 +42,9 @@ public abstract class ReportDiscord extends DefaultTask { .build(); try(Response response = client.newCall(request).execute()) { getLogger().info("report sent"); + if(!(response.code() == 200)) { + throw new HttpResponseException(response.code(), response.message()); + } } } -- 2.39.5 From 18964aa779d08c7d1f3c15f3a1bc049a8f3d9e3f Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 26 Jul 2023 23:21:14 +0200 Subject: [PATCH 2/3] Change exception to GradleException --- buildSrc/src/main/java/fr/altarik/ReportDiscord.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java index d5c49b5..122217f 100644 --- a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java +++ b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java @@ -2,10 +2,10 @@ package fr.altarik; import okhttp3.*; import org.gradle.api.DefaultTask; +import org.gradle.api.GradleException; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; -import org.gradle.internal.impldep.org.apache.http.client.HttpResponseException; import java.io.IOException; @@ -43,7 +43,7 @@ public abstract class ReportDiscord extends DefaultTask { try(Response response = client.newCall(request).execute()) { getLogger().info("report sent"); if(!(response.code() == 200)) { - throw new HttpResponseException(response.code(), response.message()); + throw new GradleException("Discord returned a " + response.code() + " code: " + response.message()); } } } -- 2.39.5 From bb9ae4d59b2176930ded68c039edcac14192c6ed Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 26 Jul 2023 23:22:49 +0200 Subject: [PATCH 3/3] Doesn't return an exception if 20X --- buildSrc/src/main/java/fr/altarik/ReportDiscord.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java index 122217f..15ad0c1 100644 --- a/buildSrc/src/main/java/fr/altarik/ReportDiscord.java +++ b/buildSrc/src/main/java/fr/altarik/ReportDiscord.java @@ -42,7 +42,7 @@ public abstract class ReportDiscord extends DefaultTask { .build(); try(Response response = client.newCall(request).execute()) { getLogger().info("report sent"); - if(!(response.code() == 200)) { + if(!response.isSuccessful()) { throw new GradleException("Discord returned a " + response.code() + " code: " + response.message()); } } -- 2.39.5