1
0
Fork 0

Adding upstream version 0.8.9.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-22 10:16:14 +02:00
parent 3b2c48b5e4
commit c0c4addb85
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
285 changed files with 25880 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package jsonclient
import (
"errors"
"fmt"
)
// Error contains additional HTTP/JSON details.
type Error struct {
StatusCode int
Body string
err error
}
// Error returns the string representation of the error.
func (je Error) Error() string {
return je.String()
}
// String provides a human-readable description of the error.
func (je Error) String() string {
if je.err == nil {
return fmt.Sprintf("unknown error (HTTP %v)", je.StatusCode)
}
return je.err.Error()
}
// ErrorBody extracts the request body from an error if its a jsonclient.Error.
func ErrorBody(e error) string {
var jsonError Error
if errors.As(e, &jsonError) {
return jsonError.Body
}
return ""
}