Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,21 @@
return &websocket.Visitor{
VisitError: func(ee websocket.ErrorElement) error {
ansi.StopSpinner(s, "", logger.Out)
switch ee.Error.(type) {

Check failure on line 236 in pkg/cmd/listen.go

View workflow job for this annotation

GitHub Actions / test (1.24.1, ubuntu-latest)

typeSwitchVar: 1 case can benefit from type switch with assignment (gocritic)

Check failure on line 236 in pkg/cmd/listen.go

View workflow job for this annotation

GitHub Actions / test (1.24.1, ubuntu-latest)

typeSwitchVar: 1 case can benefit from type switch with assignment (gocritic)
case proxy.FailedToPostError:
color := ansi.Color(os.Stdout)
localTime := time.Now().Format(timeLayout)

errStr := fmt.Sprintf("%s [%s] Failed to POST: %v\n",
postErr := ee.Error.(proxy.FailedToPostError)
errMsg := fmt.Sprintf("Failed to POST: %v", postErr)
if strings.Contains(postErr.Error(), "connection refused") {
errMsg = fmt.Sprintf("Failed to POST: Connection to %s was refused. Is your local server running?", postErr.URL)
}

errStr := fmt.Sprintf("%s [%s] %s\n",
color.Faint(localTime),
color.Red("ERROR"),
ee.Error,
errMsg,
)
fmt.Println(errStr)

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Execute(ctx context.Context) {
case requests.IsAPIKeyExpiredError(err):
fmt.Fprintln(os.Stderr, "The API key provided has expired. Obtain a new key from the Dashboard or run `stripe login` and try again.")
case isLoginRequiredError && projectNameFlag != "default":
fmt.Printf("You provided the project name \"%[1]s\" (either via the \"--project-name\" flag or the \"STRIPE_PROJECT_NAME\" environment variable), but no config for that project was found.\nPlease run `stripe login --project-name=%[1]s` to enable commands for this project.\n", projectNameFlag)
fmt.Fprintf(os.Stderr, "You provided the project name \"%[1]s\" (either via the \"--project-name\" flag or the \"STRIPE_PROJECT_NAME\" environment variable), but no config for that project was found.\nPlease run `stripe login --project-name=\"%[1]s\"` to enable commands for this project.\n", projectNameFlag)
case isLoginRequiredError:
// capitalize first letter of error because linter
errRunes := []rune(errString)
Expand All @@ -134,7 +134,7 @@ func Execute(ctx context.Context) {
showSuggestion()

default:
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
}

os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (p *Profile) GetAPIKey(livemode bool) (string, error) {
if envKey != "" {
err := validators.APIKey(envKey)
if err != nil {
return "", err
return "", fmt.Errorf("the STRIPE_API_KEY environment variable is set but invalid: %w", err)
}

return envKey, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/fixtures/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ var Events = map[string]string{
"plan.deleted": "triggers/plan.deleted.json",
"plan.updated": "triggers/plan.updated.json",
"price.created": "triggers/price.created.json",
"price.deleted": "triggers/price.deleted.json",
"price.updated": "triggers/price.updated.json",
"product.created": "triggers/product.created.json",
"product.deleted": "triggers/product.deleted.json",
Expand Down
31 changes: 31 additions & 0 deletions pkg/fixtures/triggers/price.deleted.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"_meta": {
"template_version": 0
},
"fixtures": [
{
"name": "product",
"path": "/v1/products",
"method": "post",
"params": {
"name": "myproduct",
"description": "(created by Stripe CLI)"
}
},
{
"name": "price",
"path": "/v1/prices",
"method": "post",
"params": {
"product": "${product:id}",
"unit_amount": "1500",
"currency": "usd"
}
},
{
"name": "product_deleted",
"path": "/v1/products/${product:id}",
"method": "delete"
}
]
}
3 changes: 2 additions & 1 deletion pkg/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

// Login is the main entrypoint for logging in to the CLI.
func Login(ctx context.Context, baseURL string, config *config.Config) error {
links, err := GetLinks(ctx, baseURL, config.Profile.DeviceName)
deviceName, _ := config.Profile.GetDeviceName()
links, err := GetLinks(ctx, baseURL, deviceName)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/proxy/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (f EndpointResponseHandlerFunc) ProcessResponse(evtCtx eventContext, forwar
// FailedToPostError describes a failure to send a POST request to an endpoint
type FailedToPostError struct {
Err error
URL string
}

func (f FailedToPostError) Error() string {
Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *EndpointClient) Post(evtCtx eventContext) error {
resp, err := c.cfg.HTTPClient.Do(req)
if err != nil {
c.cfg.OutCh <- websocket.ErrorElement{
Error: FailedToPostError{Err: err},
Error: FailedToPostError{Err: err, URL: c.URL},
}
return err
}
Expand Down Expand Up @@ -158,7 +159,7 @@ func (c *EndpointClient) PostV2(evtCtx eventContext) error {
resp, err := http.DefaultClient.Do(req)
if err != nil {
c.cfg.OutCh <- websocket.ErrorElement{
Error: FailedToPostError{Err: err},
Error: FailedToPostError{Err: err, URL: c.URL},
}
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (p *Proxy) Run(ctx context.Context) error {
displayedAPIVersion := ""
if p.cfg.UseLatestAPIVersion && session.LatestVersion != "" {
displayedAPIVersion = "You are using Stripe API Version [" + session.LatestVersion + "]. "
} else if !p.cfg.UseLatestAPIVersion && session.DefaultVersion != "" {
} else if session.DefaultVersion != "" {
displayedAPIVersion = "You are using Stripe API Version [" + session.DefaultVersion + "]. "
}

Expand Down
Loading