Skip to content

Commit

Permalink
http-backend: http backend lock error return LockError instead of gen…
Browse files Browse the repository at this point in the history
…eric error
  • Loading branch information
nvanheuverzwijn committed Jun 16, 2022
1 parent 0d3d954 commit bb1c134
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/backend/remote-state/http/client.go
Expand Up @@ -100,14 +100,23 @@ func (c *httpClient) Lock(info *statemgr.LockInfo) (string, error) {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("HTTP remote state already locked, failed to read body")
return "", &statemgr.LockError{
Info: info,
Err: fmt.Errorf("HTTP remote state already locked, failed to read body"),
}
}
existing := statemgr.LockInfo{}
err = json.Unmarshal(body, &existing)
if err != nil {
return "", fmt.Errorf("HTTP remote state already locked, failed to unmarshal body")
return "", &statemgr.LockError{
Info: info,
Err: fmt.Errorf("HTTP remote state already locked, failed to unmarshal body"),
}
}
return "", &statemgr.LockError{
Info: info,
Err: fmt.Errorf("HTTP remote state already locked: ID=%s", existing.ID),
}
return "", fmt.Errorf("HTTP remote state already locked: ID=%s", existing.ID)
default:
return "", fmt.Errorf("Unexpected HTTP response code %d", resp.StatusCode)
}
Expand Down

0 comments on commit bb1c134

Please sign in to comment.