Skip to content

Commit

Permalink
refactored all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Aug 12, 2024
1 parent 173aced commit 650b0c3
Show file tree
Hide file tree
Showing 15 changed files with 972 additions and 1,028 deletions.
4 changes: 4 additions & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ package api

import (
"encoding/json"
"errors"
)

var ErrPreconditionFailed = errors.New("Precondition Failed")

type ConfigHandler interface {
json.Marshaler
json.Unmarshaler
Expand All @@ -31,5 +34,6 @@ type ConfigHandler interface {
UnmarshalJSONPath(path string, data []byte) error

Fingerprint() string
// DoLockedAction will execute callback if the fingerprint matches, or return ErrPreconditionFailed
DoLockedAction(fingerprint string, callback func(ConfigHandler) error) error
}
13 changes: 10 additions & 3 deletions cluster/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func redirectChecker(req *http.Request, via []*http.Request) error {
return nil
}

func (cr *Cluster) getFullURL(relpath string) (u *url.URL, err error) {
if u, err = url.Parse(cr.opts.Server); err != nil {
return
}
u.Path = path.Join(u.Path, relpath)
return
}

func (cr *Cluster) makeReq(ctx context.Context, method string, relpath string, query url.Values) (req *http.Request, err error) {
return cr.makeReqWithBody(ctx, method, relpath, query, nil)
}
Expand All @@ -89,11 +97,10 @@ func (cr *Cluster) makeReqWithBody(
method string, relpath string,
query url.Values, body io.Reader,
) (req *http.Request, err error) {
var u *url.URL
if u, err = url.Parse(cr.opts.Server); err != nil {
u, err := cr.getFullURL(relpath)
if err != nil {
return
}
u.Path = path.Join(u.Path, relpath)
if query != nil {
u.RawQuery = query.Encode()
}
Expand Down
Loading

0 comments on commit 650b0c3

Please sign in to comment.