Skip to content

Commit c582329

Browse files
feat: improve api error handling
1 parent 14e044e commit c582329

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/plugin/discovery/discovery.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
)
2828

2929
const PluginDir = ".semrel"
30+
const PluginAPI = "https://plugins.go-semantic-release.xyz/api/v1"
3031

3132
var osArchDir = runtime.GOOS + "_" + runtime.GOARCH
3233

@@ -73,14 +74,17 @@ type apiPlugin struct {
7374
}
7475

7576
func getPluginInfo(name string) (*apiPlugin, error) {
76-
res, err := http.Get(fmt.Sprintf("https://plugins.go-semantic-release.xyz/api/v1/plugins/%s.json", name))
77+
res, err := http.Get(fmt.Sprintf("%s/plugins/%s.json", PluginAPI, name))
7778
if err != nil {
7879
return nil, err
7980
}
81+
defer res.Body.Close()
82+
if res.StatusCode == 404 {
83+
return nil, fmt.Errorf("plugin not found: %s", name)
84+
}
8085
if res.StatusCode < 200 || res.StatusCode >= 300 {
8186
return nil, errors.New("invalid response")
8287
}
83-
defer res.Body.Close()
8488
var plugin *apiPlugin
8589
if err := json.NewDecoder(res.Body).Decode(&plugin); err != nil {
8690
return nil, err

0 commit comments

Comments
 (0)