Skip to content

Commit 4c0b3cf

Browse files
committed
chore: remove panics
1 parent 7459d4d commit 4c0b3cf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

steam/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"net/http"
55
"net/url"
66
"time"
7+
8+
"github.com/kldzj/pzmod/util"
9+
"github.com/spf13/cobra"
710
)
811

912
const (
@@ -19,7 +22,7 @@ func SetApiKey(key string) {
1922

2023
func getApiKey() string {
2124
if steamApiKey == "" {
22-
panic("Steam API key not set")
25+
cobra.CheckErr(util.ErrNoApiKey)
2326
}
2427

2528
return steamApiKey
@@ -32,7 +35,7 @@ func newHttpClient() *http.Client {
3235
func constructSteamApiUrl(path string) (*url.URL, *url.Values) {
3336
url, err := url.Parse("https://api.steampowered.com" + path)
3437
if err != nil {
35-
panic(err)
38+
cobra.CheckErr(err)
3639
}
3740

3841
query := url.Query()

util/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ var (
99
ErrFileExists = errors.New("file already exists")
1010
ErrInvalidKey = errors.New("invalid key")
1111
ErrVerNotSet = errors.New("version not set")
12+
ErrNoApiKey = errors.New("no Steam API key set")
1213
)

0 commit comments

Comments
 (0)