Skip to content

Commit 9f96c96

Browse files
committed
Improve token error
1 parent 43c1e77 commit 9f96c96

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/iot/token.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package iot
1919

2020
import (
2121
"context"
22+
"fmt"
2223
"net/url"
24+
"strings"
2325

2426
"golang.org/x/oauth2"
2527
cc "golang.org/x/oauth2/clientcredentials"
@@ -37,5 +39,9 @@ func token(client, secret string) (*oauth2.Token, error) {
3739
EndpointParams: additionalValues,
3840
}
3941
// Get the access token in exchange of client_id and client_secret
40-
return config.Token(context.Background())
42+
t, err := config.Token(context.Background())
43+
if err != nil && strings.Contains(err.Error(), "401") {
44+
return nil, fmt.Errorf("wrong credentials")
45+
}
46+
return t, err
4147
}

0 commit comments

Comments
 (0)