fix(http): tell a missing snapshot API from its status, not from the error text

The error message carries the request path, so a snapshot named nightly404 turned a real server error into 'not available'. FlociException now carries the HTTP status and the snapshot commands ask that.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura committed 2026-10-10 21:29:34 -05:00
1 parent c3e74e4815
commit 66cf79ac14
7 files changed
+58 -7

No files matched your search

@@ -47,7 +47,7 @@ public class SnapshotDeleteCommand implements Callable<Integer> {
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
if (e.endpointMissing()) {
printer.error("Snapshot API not available on this server version.\n" +
"Track progress: " + profile.serverRepo() + "/issues");
} else {
@@ -54,7 +54,7 @@ public class SnapshotListCommand implements Callable<Integer> {
node.forEach(s -> printer.println(" " + s.asText()));
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
if (e.endpointMissing()) {
printer.error("Snapshot API not available on this server version.\n" +
"Track progress: " + profile.serverRepo() + "/issues");
} else {
@@ -47,7 +47,7 @@ public class SnapshotLoadCommand implements Callable<Integer> {
printer.println(Ansi.green("Snapshot loaded:") + " " + name);
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
if (e.endpointMissing()) {
printer.error("Snapshot API not available on this server version.\n" +
"Track progress: " + profile.serverRepo() + "/issues");
} else {
@@ -54,7 +54,7 @@ public class SnapshotSaveCommand implements Callable<Integer> {
printer.println(Ansi.green("Snapshot saved:") + " " + name);
return 0;
} catch (FlociException e) {
if (e.getMessage().contains("404") || e.getMessage().contains("501")) {
if (e.endpointMissing()) {
printer.error("Snapshot API not available on this server version.\n" +
"Track progress: " + profile.serverRepo() + "/issues");
} else {
@@ -1,7 +1,29 @@
package io.floci.cli.http;
public class FlociException extends Exception {
private final int status;
public FlociException(String message) {
this(message, 0);
}
/** An error the server answered with HTTP {@code status}. */
public FlociException(String message, int status) {
super(message);
this.status = status;
}
/** The HTTP status the server answered with, or 0 when the failure was not an HTTP response. */
public int status() {
return status;
}
/**
* The server has no such endpoint (404) or does not implement it (501). Asked of the status,
* never of the message: the message carries the request path, and a path can contain "404".
*/
public boolean endpointMissing() {
return status == 404 || status == 501;
}
}
@@ -164,7 +164,7 @@ public class FlociHttpClient {
message.contains("not available yet"));
}
if (resp.statusCode() >= 400) {
throw new FlociException("Server returned HTTP " + resp.statusCode() + " for " + path);
throw new FlociException("Server returned HTTP " + resp.statusCode() + " for " + path, resp.statusCode());
}
return resp.body();
} catch (FlociException e) {
@@ -295,7 +295,7 @@ public class FlociHttpClient {
+ "Point --endpoint at the address Floci listens on.");
}
if (status >= 400) {
throw new FlociException("Server returned HTTP " + status + " for " + path);
throw new FlociException("Server returned HTTP " + status + " for " + path, status);
}
}