Skip to content

A local-first personal finance app

Handling tunnel errors as network failure (#3697)

Michael Clark1895bc80c209
diff --git a/packages/loot-core/src/server/post.ts b/packages/loot-core/src/server/post.ts
index 8b49c359d4..1fa28cd22a 100644
--- a/packages/loot-core/src/server/post.ts
+++ b/packages/loot-core/src/server/post.ts
@@ -15,6 +15,19 @@ function throwIfNot200(res, text) {
const json = JSON.parse(text);
throw new PostError(json.reason);
}
+
+ // Actual Sync Server may be exposed via a tunnel (e.g. ngrok). Tunnel errors should be treated as network errors.
+ const tunnelErrorHeaders = ['ngrok-error-code'];
+ const tunnelError = tunnelErrorHeaders.some(header =>
+ res.headers.has(header),
+ );
+
+ if (tunnelError) {
+ // Tunnel errors are present when the tunnel is active and the server is not reachable e.g. server is offline
+ // When we experience a tunnel error we treat it as a network failure
+ throw new PostError('network-failure');
+ }
+
throw new PostError(text);
}
}
diff --git a/upcoming-release-notes/3697.md b/upcoming-release-notes/3697.md
new file mode 100644
index 0000000000..7db7e739fc
--- /dev/null
+++ b/upcoming-release-notes/3697.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MikesGlitch]
+---
+
+Supporting the use of an ngrok tunnel when used to tunnel into actual-sync server