Skip to content

Commit

Permalink
fix: fctl fix errors from sdks (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Jul 25, 2023
1 parent 5936ac8 commit 13239d1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
16 changes: 15 additions & 1 deletion components/fctl/cmd/ledger/internal/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,27 @@ func CreateTransaction(client *formance.Formance, ctx context.Context, request o
if err != nil {
return nil, err
}

if v.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", v.ErrorResponse.ErrorCode, v.ErrorResponse.ErrorMessage)
}

if v.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", v.StatusCode)
}

return &v.CreateTransactionResponse.Data[0], nil
} else {
response, err := client.Ledger.CreateTransaction(ctx, request)
if err != nil {
return nil, err
}
if response.StatusCode > 300 {

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code %d when creating transaction", response.StatusCode)
}

Expand Down
10 changes: 10 additions & 0 deletions components/fctl/cmd/ledger/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ledger

import (
"fmt"

fctl "github.com/formancehq/fctl/pkg"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,6 +69,14 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
return nil, err
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode)
}

c.store.Ledgers = response.ConfigInfoResponse.Data.Config.Storage.Ledgers

return c, nil
Expand Down
8 changes: 8 additions & 0 deletions components/fctl/cmd/ledger/serverinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ func (c *ServerInfoController) Run(cmd *cobra.Command, args []string) (fctl.Rend
return nil, err
}

if response.ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.ErrorResponse.ErrorCode, response.ErrorResponse.ErrorMessage)
}

if response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode)
}

c.store.Server = response.ConfigInfoResponse.Data.Server
c.store.Version = response.ConfigInfoResponse.Data.Version
c.store.StorageDriver = response.ConfigInfoResponse.Data.Config.Storage.Driver
Expand Down
12 changes: 12 additions & 0 deletions components/fctl/cmd/orchestration/instances/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (c *InstancesDescribeController) Run(cmd *cobra.Command, args []string) (fc
return nil, err
}

if response.Error != nil {
return nil, fmt.Errorf("%s: %s", response.Error.ErrorCode, response.Error.ErrorMessage)
}

if response.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", response.StatusCode)
}
Expand Down Expand Up @@ -192,6 +196,14 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
return err
}

if stageResponse.Error != nil {
return fmt.Errorf("%s: %s", stageResponse.Error.ErrorCode, stageResponse.Error.ErrorMessage)
}

if stageResponse.StatusCode >= 300 {
return fmt.Errorf("unexpected status code: %d", stageResponse.StatusCode)
}

for _, historyStage := range stageResponse.GetWorkflowInstanceHistoryStageResponse.Data {
switch {
case historyStage.Input.StripeTransfer != nil:
Expand Down
9 changes: 8 additions & 1 deletion components/fctl/cmd/orchestration/instances/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ func (c *InstancesShowController) Run(cmd *cobra.Command, args []string) (fctl.R
res, err := client.Orchestration.GetInstance(cmd.Context(), operations.GetInstanceRequest{
InstanceID: args[0],
})

if err != nil {
return nil, errors.Wrap(err, "reading instance")
}

if res.Error != nil {
return nil, fmt.Errorf("%s: %s", res.Error.ErrorCode, res.Error.ErrorMessage)
}

if res.StatusCode >= 300 {
return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

c.store.WorkflowInstance = res.GetWorkflowInstanceResponse.Data
response, err := client.Orchestration.GetWorkflow(cmd.Context(), operations.GetWorkflowRequest{
FlowID: res.GetWorkflowInstanceResponse.Data.WorkflowID,
Expand Down
8 changes: 8 additions & 0 deletions components/fctl/cmd/orchestration/workflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func (c *WorkflowsRunController) Render(cmd *cobra.Command, args []string) error
panic(err)
}

if w.Error != nil {
panic(fmt.Sprintf("%s: %s", w.Error.ErrorCode, w.Error.ErrorMessage))
}

if w.StatusCode >= 300 {
panic(fmt.Sprintf("unexpected status code: %d", w.StatusCode))
}

return internal.PrintWorkflowInstance(cmd.OutOrStdout(), w.GetWorkflowResponse.Data, c.store.WorkflowInstance)
}
return nil
Expand Down

0 comments on commit 13239d1

Please sign in to comment.