diff --git a/CHANGELOG.md b/CHANGELOG.md index db73aefd..661007d5 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,15 @@ 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 + +### 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 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 {