From 6a67e1621f4acd44085363879d8e17c2b45adf83 Mon Sep 17 00:00:00 2001 From: Damian Orzepowski Date: Mon, 15 Sep 2025 16:32:47 +0200 Subject: [PATCH 1/3] fix: AuthFetch should fallback to non auth call when initial handshake return non ok http status --- auth/clients/authhttp/authhttp.go | 2 +- auth/transports/errors.go | 7 +++++-- auth/transports/simplified_http_transport.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/auth/clients/authhttp/authhttp.go b/auth/clients/authhttp/authhttp.go index cbd16efe..b2b37875 100644 --- a/auth/clients/authhttp/authhttp.go +++ b/auth/clients/authhttp/authhttp.go @@ -435,7 +435,7 @@ func (a *AuthFetch) Fetch(ctx context.Context, urlStr string, config *Simplified err error }{resp, retryErr} return - } else if strings.Contains(err.Error(), "HTTP server failed to authenticate") { + } else if errors.Is(err, transports.ErrHTTPServerFailedToAuthenticate) { // Fall back to regular HTTP request resp, fallbackErr := a.handleFetchAndValidate(urlStr, config, peerToUse) responseChan <- struct { diff --git a/auth/transports/errors.go b/auth/transports/errors.go index 4b599f2b..159e3b41 100644 --- a/auth/transports/errors.go +++ b/auth/transports/errors.go @@ -1,10 +1,13 @@ // Package transports provides implementations of the auth.Transport interface package transports -import "errors" +import ( + "errors" +) // Common errors for all transports var ( // ErrNoHandlerRegistered is returned when trying to send a message without registering an OnData handler - ErrNoHandlerRegistered = errors.New("no OnData handler registered") + ErrNoHandlerRegistered = errors.New("no OnData handler registered") + ErrHTTPServerFailedToAuthenticate = errors.New("HTTP server failed to authenticate") ) diff --git a/auth/transports/simplified_http_transport.go b/auth/transports/simplified_http_transport.go index 21cba600..f6db2dbc 100644 --- a/auth/transports/simplified_http_transport.go +++ b/auth/transports/simplified_http_transport.go @@ -121,7 +121,7 @@ func (t *SimplifiedHTTPTransport) authMessageFromNonGeneralMessageResponse(resp if resp.StatusCode < 200 || resp.StatusCode >= 300 { body, _ := io.ReadAll(resp.Body) - return responseMsg, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body)) + return responseMsg, errors.Join(ErrHTTPServerFailedToAuthenticate, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body))) } if resp.ContentLength == 0 { From 66f0acf3793176c427df5c0dde20f0f582e341b8 Mon Sep 17 00:00:00 2001 From: Luke Rohenaz Date: Tue, 16 Sep 2025 12:49:00 -0400 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db73aefd..c4c45fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. The format ## Table of Contents +- [1.2.10 - 2025-09-16](#1210---2025-09-16) - [1.2.9 - 2025-09-07](#129---2025-09-07) - [1.2.8 - 2025-08-07](#128---2025-08-07) - [1.2.7 - 2025-08-05](#127---2025-08-05) @@ -44,6 +45,17 @@ All notable changes to this project will be documented in this file. The format - [1.1.0 - 2024-08-19](#110---2024-08-19) - [1.0.0 - 2024-06-06](#100---2024-06-06) +## [1.2.10] - 2025-09-16 + +### Added +- New error type `ErrHTTPServerFailedToAuthenticate` for authentication failures +- `errors.Join()` usage in `simplified_http_transport.go` +- `errors.Is()` type checking in `authhttp.go` + +### Changed +- Updated error return to include the new error type using `errors.Join()` +- Replaced string-based error checking with proper `errors.Is()` type checking + ## [1.2.9] - 2025-09-07 ### Added From 70377d5331a74e572edca380fa364fe2ebd9a68a Mon Sep 17 00:00:00 2001 From: Luke Rohenaz Date: Tue, 16 Sep 2025 12:51:00 -0400 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c45fe1..661007d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,8 +49,6 @@ All notable changes to this project will be documented in this file. The format ### Added - New error type `ErrHTTPServerFailedToAuthenticate` for authentication failures -- `errors.Join()` usage in `simplified_http_transport.go` -- `errors.Is()` type checking in `authhttp.go` ### Changed - Updated error return to include the new error type using `errors.Join()`