Improve error handling with xerrors package

- Replace custom error handling with xerrors package
- Enhance error descriptions for better debugging
- Add text utilities for string processing
- Update error tests to use standard errors package
- Add String() method to GeminiError
This commit is contained in:
2025-05-22 12:45:46 +03:00
committed by antanst
parent 4ef3f70f1f
commit 5f4da4f806
2 changed files with 42 additions and 3 deletions

View File

@@ -1,9 +1,8 @@
package gemini
import (
"errors"
"fmt"
"github.com/antanst/go_errors"
)
// GeminiError is used to represent
@@ -20,6 +19,10 @@ func (e *GeminiError) Error() string {
return fmt.Sprintf("gemini error: code %d %s", e.Code, e.Msg)
}
func (e *GeminiError) String() string {
return e.Error()
}
// NewGeminiError creates a new GeminiError based on the status code and header.
// Status codes are based on the Gemini protocol specification:
// - 1x: Input required
@@ -57,5 +60,5 @@ func IsGeminiError(err error) bool {
return false
}
var asError *GeminiError
return go_errors.As(err, &asError)
return errors.As(err, &asError)
}