Skip to content

Colota - Android GPS Location tracker

fix(connection): log only the status of a failed test connection (#920)

Max Dietrich94c51820367b
diff --git a/apps/mobile/src/components/features/settings/ConnectionSettings.tsx b/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
index b1a97d5b..e41c6920 100644
--- a/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
+++ b/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
@@ -198,6 +198,8 @@ export function ConnectionSettings({
Keyboard.dismiss()
if (testBlocker || !(await commitDraft())) return
const endpoint = draft.trim()
+ // Log only the scheme, never the endpoint or the server's reply.
+ const scheme = endpoint.toLowerCase().startsWith("https://") ? "https" : "http"
setTest({ kind: "testing" })
try {
@@ -252,7 +254,7 @@ export function ConnectionSettings({
}
const result = await NativeLocationService.testEndpoint({ endpoint, method, apiFormat, payload, customFields })
- if (!result.ok) logger.warn("[ConnectionSettings] Test failed:", result.status, result.errorMessage)
+ if (!result.ok) logger.warn("[ConnectionSettings] Test failed:", result.status, scheme)
setTest({
kind: "done",
ok: result.ok,
@@ -264,7 +266,7 @@ export function ConnectionSettings({
})
} catch (err: any) {
const msg = err?.message || t("common.unknownError")
- logger.warn("[ConnectionSettings] Test failed:", err?.name, msg)
+ logger.warn("[ConnectionSettings] Test failed:", err?.code, scheme)
setTest({
kind: "done",
ok: false,
diff --git a/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx b/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
index a2ba9ac4..b8d2d27b 100644
--- a/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
+++ b/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
@@ -290,6 +290,36 @@ describe("ConnectionSettings", () => {
expect(api.queryByText("Not reachable")).toBeNull()
})
+ it("logs a failed test with its status and scheme only, never the server's words", async () => {
+ const { logger } = require("../../../../utils/logger")
+ mockTestEndpoint.mockResolvedValueOnce({
+ ok: false,
+ status: 401,
+ errorMessage: "Server returned 401: token abc123"
+ })
+ const api = renderComponent()
+
+ fireEvent.press(api.getByTestId("test-connection-btn"))
+ await api.findByText("Not reachable")
+
+ expect(logger.warn).toHaveBeenCalledWith("[ConnectionSettings] Test failed:", 401, "https")
+ expect(JSON.stringify(logger.warn.mock.calls)).not.toContain("abc123")
+ })
+
+ it("logs a thrown test failure without its message", async () => {
+ const { logger } = require("../../../../utils/logger")
+ mockTestEndpoint.mockRejectedValueOnce(
+ Object.assign(new Error("https://example.com/api?key=abc123"), { code: "E_TEST_ENDPOINT" })
+ )
+ const api = renderComponent()
+
+ fireEvent.press(api.getByTestId("test-connection-btn"))
+ await api.findByText("Not reachable")
+
+ expect(logger.warn).toHaveBeenCalledWith("[ConnectionSettings] Test failed:", "E_TEST_ENDPOINT", "https")
+ expect(JSON.stringify(logger.warn.mock.calls)).not.toContain("abc123")
+ })
+
it("falls back to the status code when the server sends no sentence", async () => {
mockTestEndpoint.mockResolvedValue({ ok: false, status: 401 })
const api = renderComponent()