From dde1517ccc6d0dbb5b8f96cd7d477b6522b8de36 Mon Sep 17 00:00:00 2001 From: Christian Lechner Date: Mon, 4 Sep 2023 09:22:24 +0200 Subject: [PATCH] feat: handle outdated client protocol version (#400) --- internal/btpcli/client.go | 11 +++++++---- internal/btpcli/client_test.go | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/btpcli/client.go b/internal/btpcli/client.go index 420870f1..1deeb73b 100644 --- a/internal/btpcli/client.go +++ b/internal/btpcli/client.go @@ -44,6 +44,8 @@ const ( HeaderCLIBackendStatus string = "X-Cpcli-Backend-Status" HeaderCLIBackendMessage string = "X-Cpcli-Backend-Message" HeaderCLIBackendMediaType string = "X-Cpcli-Backend-Mediatype" + HeaderCLIClientUpdate string = "X-Cpcli-Client-Update" + HeaderCLIServerMessage string = "X-Cpcli-Server-Message" ) const cliTargetProtocolVersion string = "v2.38.0" @@ -157,10 +159,11 @@ func (v2 *v2Client) Login(ctx context.Context, loginReq *LoginRequest) (*LoginRe var loginResponse LoginResponse err = v2.parseResponse(ctx, res, &loginResponse, http.StatusOK, map[int]string{ - http.StatusUnauthorized: "Login failed. Check your credentials.", - http.StatusForbidden: fmt.Sprintf("You cannot access global account '%s'. Make sure you have at least read access to the global account, a directory, or a subaccount.", loginReq.GlobalAccountSubdomain), - http.StatusNotFound: fmt.Sprintf("Global account '%s' not found. Try again and make sure to provide the global account's subdomain.", loginReq.GlobalAccountSubdomain), - http.StatusGatewayTimeout: "Login timed out. Please try again later.", + http.StatusUnauthorized: "Login failed. Check your credentials.", + http.StatusForbidden: fmt.Sprintf("You cannot access global account '%s'. Make sure you have at least read access to the global account, a directory, or a subaccount.", loginReq.GlobalAccountSubdomain), + http.StatusNotFound: fmt.Sprintf("Global account '%s' not found. Try again and make sure to provide the global account's subdomain.", loginReq.GlobalAccountSubdomain), + http.StatusPreconditionFailed: "Login failed due to outdated provider version. Update to the latest version of the provider.", + http.StatusGatewayTimeout: "Login timed out. Please try again later.", }) if err != nil { diff --git a/internal/btpcli/client_test.go b/internal/btpcli/client_test.go index e57f56b6..c73dce10 100644 --- a/internal/btpcli/client_test.go +++ b/internal/btpcli/client_test.go @@ -128,6 +128,14 @@ func TestV2Client_Login(t *testing.T) { expectErrorMsg: "Global account 'subdomain' not found. Try again and make sure to provide the global account's subdomain. [Status: 404; Correlation ID: fake-correlation-id]", }, }, + { + description: "error path - outdated protocol version [412]", + loginRequest: NewLoginRequest("subdomain", "john.doe", "pass"), + simulation: v2SimulationConfig{ + srvReturnStatus: http.StatusPreconditionFailed, + expectErrorMsg: "Login failed due to outdated provider version. Update to the latest version of the provider. [Status: 412; Correlation ID: fake-correlation-id]", + }, + }, { description: "error path - login request times out [504]]", loginRequest: NewLoginRequest("subdomain", "john.doe", "pass"),