Skip to content

Commit

Permalink
feat(openapi): treat all responses as speakeasy error (#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Apr 8, 2024
1 parent a4439d0 commit bf210b0
Show file tree
Hide file tree
Showing 315 changed files with 736 additions and 3,617 deletions.
10 changes: 0 additions & 10 deletions components/fctl/cmd/ledger/accounts/list.go
@@ -1,8 +1,6 @@
package accounts

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/collectionutils"

"github.com/formancehq/fctl/cmd/ledger/internal"
Expand Down Expand Up @@ -76,14 +74,6 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
return nil, err
}

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

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

c.store.Accounts = rsp.AccountsCursorResponse.Cursor.Data

return c, nil
Expand Down
10 changes: 0 additions & 10 deletions components/fctl/cmd/ledger/accounts/set_metadata.go
@@ -1,8 +1,6 @@
package accounts

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/collectionutils"

"github.com/formancehq/fctl/cmd/ledger/internal"
Expand Down Expand Up @@ -72,14 +70,6 @@ func (c *SetMetadataController) Run(cmd *cobra.Command, args []string) (fctl.Ren
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.Success = response.StatusCode == 204

return c, nil
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/accounts/show.go
Expand Up @@ -58,14 +58,6 @@ func (c *ShowController) 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.Account = &response.AccountResponse.Data

return c, nil
Expand Down
12 changes: 1 addition & 11 deletions components/fctl/cmd/ledger/create.go
@@ -1,8 +1,6 @@
package ledger

import (
"fmt"

fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/shared"
Expand Down Expand Up @@ -65,7 +63,7 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
return nil, err
}

response, err := store.Client().Ledger.V2CreateLedger(cmd.Context(), operations.V2CreateLedgerRequest{
_, err = store.Client().Ledger.V2CreateLedger(cmd.Context(), operations.V2CreateLedgerRequest{
V2CreateLedgerRequest: &shared.V2CreateLedgerRequest{
Bucket: pointer.For(fctl.GetString(cmd, bucketNameFlag)),
Metadata: metadata,
Expand All @@ -76,14 +74,6 @@ func (c *CreateController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
return nil, err
}

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

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

return c, nil
}

Expand Down
4 changes: 0 additions & 4 deletions components/fctl/cmd/ledger/internal/transaction.go
Expand Up @@ -33,10 +33,6 @@ func TransactionIDOrLastN(ctx context.Context, ledgerClient *formance.Formance,
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)
}
Expand Down
9 changes: 0 additions & 9 deletions components/fctl/cmd/ledger/list.go
@@ -1,7 +1,6 @@
package ledger

import (
"fmt"
"time"

"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
Expand Down Expand Up @@ -54,14 +53,6 @@ func (c *ListController) Run(cmd *cobra.Command, args []string) (fctl.Renderable
return nil, err
}

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

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

c.store.Ledgers = response.V2LedgerListResponse.Cursor.Data

return c, nil
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/send.go
Expand Up @@ -104,14 +104,6 @@ func (c *SendController) 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 when creating transaction", response.StatusCode)
}

c.store.Transaction = &response.TransactionsResponse.Data[0]
return c, nil
}
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/serverinfo.go
Expand Up @@ -52,14 +52,6 @@ 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

Expand Down
10 changes: 0 additions & 10 deletions components/fctl/cmd/ledger/set_metadata.go
@@ -1,8 +1,6 @@
package ledger

import (
"fmt"

fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -64,14 +62,6 @@ func (c *SetMetadataController) Run(cmd *cobra.Command, args []string) (fctl.Ren
return nil, err
}

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

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

c.store.Success = response.StatusCode == 204
return c, nil
}
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/stats.go
Expand Up @@ -54,14 +54,6 @@ func (c *StatsController) Run(cmd *cobra.Command, args []string) (fctl.Renderabl
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.Stats = response.StatsResponse.Data

return c, nil
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/transactions/list.go
Expand Up @@ -121,14 +121,6 @@ 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.Transaction = response.TransactionsCursorResponse.Cursor

return c, nil
Expand Down
8 changes: 0 additions & 8 deletions components/fctl/cmd/ledger/transactions/num.go
Expand Up @@ -159,14 +159,6 @@ func (c *NumController) 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 when creating transaction", response.StatusCode)
}

c.store.Transaction = &response.TransactionsResponse.Data[0]

return c, nil
Expand Down
16 changes: 0 additions & 16 deletions components/fctl/cmd/ledger/transactions/revert.go
@@ -1,8 +1,6 @@
package transactions

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/pointer"

"github.com/formancehq/fctl/cmd/ledger/internal"
Expand Down Expand Up @@ -69,13 +67,6 @@ func (c *RevertController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
if err != nil {
return nil, err
}
if response.V2ErrorResponse != nil {
return nil, fmt.Errorf("%s: %s", response.V2ErrorResponse.ErrorCode, response.V2ErrorResponse.ErrorMessage)
}

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

c.store.Transaction = internal.WrapV2Transaction(response.V2RevertTransactionResponse.Data)
} else {
Expand All @@ -88,13 +79,6 @@ func (c *RevertController) Run(cmd *cobra.Command, args []string) (fctl.Renderab
if err != nil {
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.Transaction = internal.WrapV1Transaction(response.TransactionResponse.Data)
}
Expand Down
10 changes: 0 additions & 10 deletions components/fctl/cmd/ledger/transactions/set_metadata.go
@@ -1,8 +1,6 @@
package transactions

import (
"fmt"

"github.com/formancehq/stack/libs/go-libs/collectionutils"

"github.com/formancehq/fctl/cmd/ledger/internal"
Expand Down Expand Up @@ -75,14 +73,6 @@ func (c *SetMetadataController) Run(cmd *cobra.Command, args []string) (fctl.Ren
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.Success = response.StatusCode == 204
return c, nil
}
Expand Down
10 changes: 0 additions & 10 deletions components/fctl/cmd/ledger/transactions/show.go
@@ -1,8 +1,6 @@
package transactions

import (
"fmt"

"github.com/formancehq/fctl/cmd/ledger/internal"
fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
Expand Down Expand Up @@ -60,14 +58,6 @@ func (c *ShowController) 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.Transaction = response.TransactionResponse.Data

return c, nil
Expand Down
16 changes: 0 additions & 16 deletions components/fctl/cmd/orchestration/instances/describe.go
Expand Up @@ -55,14 +55,6 @@ 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)
}

c.store.WorkflowInstancesHistory = response.GetWorkflowInstanceHistoryResponse.Data

return c, nil
Expand Down Expand Up @@ -158,14 +150,6 @@ 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: 0 additions & 9 deletions components/fctl/cmd/orchestration/instances/list.go
@@ -1,7 +1,6 @@
package instances

import (
"fmt"
"time"

fctl "github.com/formancehq/fctl/pkg"
Expand Down Expand Up @@ -70,14 +69,6 @@ func (c *InstancesListController) Run(cmd *cobra.Command, args []string) (fctl.R
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)
}

c.store.WorkflowInstance = fctl.Map(response.ListRunsResponse.Data, func(src shared.WorkflowInstance) WorkflowInstance {
return WorkflowInstance{
InstanceID: src.ID,
Expand Down
12 changes: 1 addition & 11 deletions components/fctl/cmd/orchestration/instances/send_event.go
@@ -1,8 +1,6 @@
package instances

import (
"fmt"

fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/v2/pkg/models/operations"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -48,7 +46,7 @@ func (c *InstancesSendEventController) GetStore() *InstancesSendEventStore {

func (c *InstancesSendEventController) Run(cmd *cobra.Command, args []string) (fctl.Renderable, error) {
store := fctl.GetStackStore(cmd.Context())
response, err := store.Client().Orchestration.SendEvent(cmd.Context(), operations.SendEventRequest{
_, err := store.Client().Orchestration.SendEvent(cmd.Context(), operations.SendEventRequest{
RequestBody: &operations.SendEventRequestBody{
Name: args[1],
},
Expand All @@ -59,14 +57,6 @@ func (c *InstancesSendEventController) Run(cmd *cobra.Command, args []string) (f
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)
}

c.store.Success = true
c.store.InstanceID = args[0]
c.store.Event = args[1]
Expand Down

0 comments on commit bf210b0

Please sign in to comment.