Skip to content

fix(connectors): replace panics with error returns and add HTTP status code validation#402

Open
gyanranjanpanda wants to merge 1 commit into
microcks:masterfrom
gyanranjanpanda:fix/non-2xx-response-panic-401
Open

fix(connectors): replace panics with error returns and add HTTP status code validation#402
gyanranjanpanda wants to merge 1 commit into
microcks:masterfrom
gyanranjanpanda:fix/non-2xx-response-panic-401

Conversation

@gyanranjanpanda
Copy link
Copy Markdown

Summary

Fixes #401 - Six methods across pkg/connectors/microcks_client.go and pkg/connectors/keycloak_client.go previously crashed with Go panics when receiving non-2xx HTTP responses. This PR replaces all panic() calls with proper error returns and adds HTTP status code validation before JSON parsing.

Changes

pkg/connectors/microcks_client.go

  • GetKeycloakURL: Add status check, replace panics, use comma-ok assertions. Return "null" early when Keycloak disabled.
    • CreateTestResult: Add status check, replace panics, guard id extraction.
    • GetTestResult: Add status check, replace panic. Prevents silent false test failures.
    • DownloadArtifact: Replace remaining ReadAll panic.
    • redeemRefreshToken: Replace errors.CheckError() with proper error returns.

pkg/connectors/keycloak_client.go

  • ConnectAndGetToken: Add status check, replace panics, guard access_token.
    • GetOIDCConfig: Add status check, replace panics, guard assertions, fix swallowed error.
    • ConnectAndGetTokenAndRefreshToken: Add status check, replace panics, guard assertions, fix swallowed error.

Tests (18 new)

  • microcks_client_error_test.go: 16 tests for non-2xx, malformed JSON, missing fields, disabled Keycloak, redeemRefreshToken.
    • keycloak_client_test.go: 7 tests covering all Keycloak client error paths.

@github-actions
Copy link
Copy Markdown

👋 @gyanranjanpanda

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

…s code validation

Replace panic() calls with proper error returns and add HTTP response
status code validation in all API client methods that previously crashed
on non-2xx responses.

Changes:
- GetKeycloakURL: add status check, replace panics, guard type assertions
- CreateTestResult: add status check, replace panics, guard id assertion
- GetTestResult: add status check, replace panic (prevents silent false failures)
- DownloadArtifact: replace remaining ReadAll panic
- ConnectAndGetToken: add status check, replace panics, guard assertion
- GetOIDCConfig: add status check, replace panics, guard assertions, fix swallowed error
- ConnectAndGetTokenAndRefreshToken: add status check, replace panics, guard assertions, fix swallowed error

Fixes microcks#401

Signed-off-by: gyanranjanpanda <sanupanda141@gmail.com>
@gyanranjanpanda gyanranjanpanda force-pushed the fix/non-2xx-response-panic-401 branch from 0126144 to d1a15b2 Compare May 17, 2026 17:38
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.

bug: API client methods panic on non-2xx HTTP responses due to missing status code validation

1 participant