Skip to content

Commit 5c6da9f

Browse files
authored
Merge pull request #246 from bsv-blockchain/fix-inital-handshake-fallback
fix: AuthFetch should fallback to non auth call when initial handshake return non ok http status
2 parents d7b55d1 + 70377d5 commit 5c6da9f

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. The format
44

55
## Table of Contents
66

7+
- [1.2.10 - 2025-09-16](#1210---2025-09-16)
78
- [1.2.9 - 2025-09-07](#129---2025-09-07)
89
- [1.2.8 - 2025-08-07](#128---2025-08-07)
910
- [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
4445
- [1.1.0 - 2024-08-19](#110---2024-08-19)
4546
- [1.0.0 - 2024-06-06](#100---2024-06-06)
4647

48+
## [1.2.10] - 2025-09-16
49+
50+
### Added
51+
- New error type `ErrHTTPServerFailedToAuthenticate` for authentication failures
52+
53+
### Changed
54+
- Updated error return to include the new error type using `errors.Join()`
55+
- Replaced string-based error checking with proper `errors.Is()` type checking
56+
4757
## [1.2.9] - 2025-09-07
4858

4959
### Added

auth/clients/authhttp/authhttp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func (a *AuthFetch) Fetch(ctx context.Context, urlStr string, config *Simplified
435435
err error
436436
}{resp, retryErr}
437437
return
438-
} else if strings.Contains(err.Error(), "HTTP server failed to authenticate") {
438+
} else if errors.Is(err, transports.ErrHTTPServerFailedToAuthenticate) {
439439
// Fall back to regular HTTP request
440440
resp, fallbackErr := a.handleFetchAndValidate(urlStr, config, peerToUse)
441441
responseChan <- struct {

auth/transports/errors.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Package transports provides implementations of the auth.Transport interface
22
package transports
33

4-
import "errors"
4+
import (
5+
"errors"
6+
)
57

68
// Common errors for all transports
79
var (
810
// ErrNoHandlerRegistered is returned when trying to send a message without registering an OnData handler
9-
ErrNoHandlerRegistered = errors.New("no OnData handler registered")
11+
ErrNoHandlerRegistered = errors.New("no OnData handler registered")
12+
ErrHTTPServerFailedToAuthenticate = errors.New("HTTP server failed to authenticate")
1013
)

auth/transports/simplified_http_transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (t *SimplifiedHTTPTransport) authMessageFromNonGeneralMessageResponse(resp
121121

122122
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
123123
body, _ := io.ReadAll(resp.Body)
124-
return responseMsg, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body))
124+
return responseMsg, errors.Join(ErrHTTPServerFailedToAuthenticate, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body)))
125125
}
126126

127127
if resp.ContentLength == 0 {

0 commit comments

Comments
 (0)