microcks-cli
microcks-cli copied to clipboard
fix(connectors): replace panics with error returns and add HTTP status code validation
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.
👋 @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!
@Harsh4902 could u review this
@Harsh4902 could u review this now