Skip to content

Commit

Permalink
eos: properly propagate lock errors as BadRequest -> HTTP 409
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Feb 15, 2024
1 parent 4df12b1 commit 6597fea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func (c *Client) executeXRDCopy(ctx context.Context, cmdArgs []string) (string,
err = errtypes.InvalidCredentials("eosclient: no sufficient permissions for the operation")
}

// check for lock mismatch error
if strings.Contains(errBuf.String(), "file has a valid extended attribute lock") {
err = errtypes.BadRequest("eosclient: lock mismatch")
}

args := fmt.Sprintf("%s", cmd.Args)
env := fmt.Sprintf("%s", cmd.Env)
log.Info().Str("args", args).Str("env", env).Int("exit", exitStatus).Msg("eos cmd")
Expand Down
6 changes: 4 additions & 2 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func (c *EOSHTTPClient) doReq(req *http.Request, remoteuser string) (*http.Respo
return resp, err
}

// If the error is not nil, take that
// If there is an error coming from EOS, erturn a descriptive error.
// If the error is not nil, take that.
// If there is an error coming from EOS, return a descriptive error.
func (c *EOSHTTPClient) getRespError(rsp *http.Response, err error) error {
if err != nil {
return err
Expand All @@ -228,6 +228,8 @@ func (c *EOSHTTPClient) getRespError(rsp *http.Response, err error) error {
return errtypes.PermissionDenied(rspdesc(rsp))
case http.StatusNotFound:
return errtypes.NotFound(rspdesc(rsp))
case http.StatusBadRequest:
return errtypes.BadRequest(rspdesc(rsp))
}

return errtypes.InternalError("Err from EOS: " + rspdesc(rsp))
Expand Down

0 comments on commit 6597fea

Please sign in to comment.