0.1.0 | Error Message Improvements

This commit is contained in:
Patrick
2026-06-04 00:46:15 +02:00
parent f89c0ba662
commit bf7ee6e265
2 changed files with 28 additions and 13 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
}
group = 'de.winniepat'
version = '0.0.9'
version = '0.1.0'
java {
@@ -56,12 +56,16 @@ public class LicenseClient {
* @return CompletabaleFuture with the LicenseResult from the backend
*/
public static CompletableFuture<LicenseResult> checkAsync(String apiUrl, String plugin, String licenseKey, String serverId) {
HttpRequest request = createRequest(apiUrl, plugin, licenseKey, serverId);
try {
HttpRequest request = createRequest(apiUrl, plugin, licenseKey, serverId);
return HTTP_CLIENT
.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(LicenseClient::fromHttpResponse)
.exceptionally(LicenseClient::errorResult);
return HTTP_CLIENT
.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(LicenseClient::fromHttpResponse)
.exceptionally(LicenseClient::errorResult);
} catch (Exception e) {
return CompletableFuture.completedFuture(errorResult(e));
}
}
/**
@@ -94,13 +98,8 @@ public class LicenseClient {
}
private static LicenseResult errorResult(Throwable throwable) {
String msg = throwable.getMessage();
if (msg == null || msg.isBlank()) {
msg = throwable.getClass().getSimpleName();
}
return new LicenseError(msg);
String message = buildErrorMessage(throwable);
return new LicenseError(message);
}
private static String getString(JsonObject json, String key, String def) {
@@ -143,4 +142,20 @@ public class LicenseClient {
return uri;
}
private static String buildErrorMessage(Throwable t) {
Throwable root = t;
while (root.getCause() != null) {
root = root.getCause();
}
String msg = root.getMessage();
if (msg == null || msg.isBlank()) {
msg = root.getClass().getSimpleName();
}
return root.getClass().getSimpleName() + ": " + msg;
}
}