Skip to content

Commit

Permalink
fix: display API error reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Enda Phelan committed Dec 14, 2020
1 parent 8056bc8 commit b70493b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"kafka",
"list"
]
},
{
"name": "Describe Kafka",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/rhoas",
"env": {},
"args": [
"kafka",
"describe"
]
}
]
}
23 changes: 21 additions & 2 deletions cmd/rhoas/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"errors"
"fmt"
"os"

"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/managedservices"

"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/cmd/root"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/config"
"github.com/bf2fc6cc711aee1a0c2a/cli/pkg/version"
Expand All @@ -26,9 +29,25 @@ func main() {
generateDocumentation(rootCmd)
}

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
err := rootCmd.Execute()
if err == nil {
return
}

// Attempt to unwrap the descriptive API error message
var apiError managedservices.GenericOpenAPIError
if ok := errors.As(err, &apiError); ok {
errModel := apiError.Model()

e, ok := errModel.(managedservices.Error)
if ok {
fmt.Fprintf(os.Stderr, "Error: %v\n", e.Reason)
os.Exit(1)
}
}

fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}

func initConfig() {
Expand Down

0 comments on commit b70493b

Please sign in to comment.