Skip to content

fix(api): log test-connection failures with provider context#432

Open
funkypenguin wants to merge 1 commit into
nzbdav-dev:mainfrom
elfhosted:fix/log-test-connection-failures
Open

fix(api): log test-connection failures with provider context#432
funkypenguin wants to merge 1 commit into
nzbdav-dev:mainfrom
elfhosted:fix/log-test-connection-failures

Conversation

@funkypenguin
Copy link
Copy Markdown
Contributor

Summary

The /api/test-usenet-connection endpoint silently swallows CouldNotConnectToUsenetException and CouldNotLoginToUsenetException and returns connected: false with no log line. Users hitting "Connection test failed" in the UI have no way to diagnose the actual cause — bad credentials, DNS failure, TLS handshake failure, server-side rejection, unreachable host, etc. — without attaching a debugger or packet-sniffing.

I hit this debugging a real provider misconfiguration this week: the UI showed the generic red banner and the pod logs were silent. The fix took five minutes once I knew the error message; finding the message took much longer.

Changes

backend/Api/Controllers/TestUsenetConnection/TestUsenetConnectionController.cs:

  • Add Log.Warning to the CouldNotConnectToUsenetException catch — prefixed connect error.
  • Add Log.Warning to the CouldNotLoginToUsenetException catch — prefixed login error.
  • Add a catch for unexpected non-cancellation exceptions that logs with stack trace, then rethrows so BaseApiController's existing 500 handler still runs (preserves the frontend's "Failed to test connection" branch for non-NNTP failures).

Each log line includes host, port, SSL flag, user, and the inner exception message:

Test connection failed for news.example.com:563 (ssl=True, user=alice): login error: 481 Authentication failed
Test connection failed for news.example.com:563 (ssl=True, user=alice): connect error: The remote certificate is invalid according to the validation procedure

The wire-format response is unchanged — connected: false still goes back on the typed exceptions. This is purely additive observability.

Test plan

  • dotnet build clean (0 errors, 77 pre-existing warnings)
  • Manual: test connection with deliberately wrong password → log line with login error: 481 ...
  • Manual: test connection with unreachable host → log line with connect error: ...
  • Manual: test connection with valid credentials → no warning, connected: true returned

🤖 Generated with Claude Code

The /api/test-usenet-connection endpoint silently caught both
CouldNotConnectToUsenetException and CouldNotLoginToUsenetException
and returned `connected: false` with no logging. Users seeing
"Connection test failed" in the UI had no way to diagnose the
underlying cause (bad credentials, DNS failure, TLS handshake
failure, server-side rejection, unreachable host, etc.).

Add Serilog warnings to each catch block, including host, port,
SSL flag, user, and the inner exception message. The connect and
login paths log distinct prefixes ("connect error" / "login error")
so operators can quickly tell which step failed.

Also catch unexpected non-cancellation exceptions, log with stack
trace, then rethrow so BaseApiController's existing 500 handler
still runs and the frontend continues to receive its current error
shape for non-NNTP failures.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant