X Tutup
Skip to content

Commit bdd95e1

Browse files
authored
Don't swallow duplicate key error (cli#4807)
1 parent a573eb5 commit bdd95e1

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

pkg/cmd/ssh-key/add/http.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package add
33
import (
44
"bytes"
55
"encoding/json"
6-
"errors"
76
"io"
87
"io/ioutil"
98
"net/http"
@@ -42,12 +41,7 @@ func SSHKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader, t
4241
defer resp.Body.Close()
4342

4443
if resp.StatusCode > 299 {
45-
var httpError api.HTTPError
46-
err := api.HandleHTTPError(resp)
47-
if errors.As(err, &httpError) && isDuplicateError(&httpError) {
48-
return nil
49-
}
50-
return err
44+
return api.HandleHTTPError(resp)
5145
}
5246

5347
_, err = io.Copy(ioutil.Discard, resp.Body)
@@ -57,8 +51,3 @@ func SSHKeyUpload(httpClient *http.Client, hostname string, keyFile io.Reader, t
5751

5852
return nil
5953
}
60-
61-
func isDuplicateError(err *api.HTTPError) bool {
62-
return err.StatusCode == 422 && len(err.Errors) == 1 &&
63-
err.Errors[0].Field == "key" && err.Errors[0].Message == "key is already in use"
64-
}

0 commit comments

Comments
 (0)
X Tutup