Skip to content

Commit

Permalink
fix: major usability updates for gosdk (#354)
Browse files Browse the repository at this point in the history
* fix: update connectors errors definition

* fix: move errors to errors package

* fix: remove extra wrapper for string when handling error in sdk

code returned from api is string so we need to do extra wrapper which is too verbose and doesn't give any value

* fix: rename package errors => error
  • Loading branch information
wtrocki authored Jan 31, 2022
1 parent e8acad7 commit 8028992
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 196 deletions.
80 changes: 40 additions & 40 deletions .errors/errors_connector_mgmt.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,280 +8,280 @@
"id": "4",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/4",
"code": "KAFKAS-MGMT-4",
"code": "CONNECTOR-MGMT-4",
"reason": "Forbidden to perform this action"
},
{
"id": "5",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/5",
"code": "KAFKAS-MGMT-5",
"code": "CONNECTOR-MGMT-5",
"reason": "Forbidden to create more instances than the maximum allowed"
},
{
"id": "6",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/6",
"code": "KAFKAS-MGMT-6",
"code": "CONNECTOR-MGMT-6",
"reason": "An entity with the specified unique values already exists"
},
{
"id": "7",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/7",
"code": "KAFKAS-MGMT-7",
"code": "CONNECTOR-MGMT-7",
"reason": "Resource not found"
},
{
"id": "8",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/8",
"code": "KAFKAS-MGMT-8",
"code": "CONNECTOR-MGMT-8",
"reason": "General validation failure"
},
{
"id": "9",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/9",
"code": "KAFKAS-MGMT-9",
"code": "CONNECTOR-MGMT-9",
"reason": "Unspecified error"
},
{
"id": "10",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/10",
"code": "KAFKAS-MGMT-10",
"code": "CONNECTOR-MGMT-10",
"reason": "HTTP Method not implemented for this endpoint"
},
{
"id": "11",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/11",
"code": "KAFKAS-MGMT-11",
"code": "CONNECTOR-MGMT-11",
"reason": "Account is unauthorized to perform this action"
},
{
"id": "12",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/12",
"code": "KAFKAS-MGMT-12",
"code": "CONNECTOR-MGMT-12",
"reason": "Required terms have not been accepted"
},
{
"id": "15",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/15",
"code": "KAFKAS-MGMT-15",
"code": "CONNECTOR-MGMT-15",
"reason": "Account authentication could not be verified"
},
{
"id": "17",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/17",
"code": "KAFKAS-MGMT-17",
"code": "CONNECTOR-MGMT-17",
"reason": "Unable to read request body"
},
{
"id": "21",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/21",
"code": "KAFKAS-MGMT-21",
"code": "CONNECTOR-MGMT-21",
"reason": "Bad request"
},
{
"id": "23",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/23",
"code": "KAFKAS-MGMT-23",
"code": "CONNECTOR-MGMT-23",
"reason": "Failed to parse search query"
},
{
"id": "24",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/24",
"code": "KAFKAS-MGMT-24",
"code": "CONNECTOR-MGMT-24",
"reason": "The maximum number of allowed kafka instances has been reached"
},
{
"id": "25",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/25",
"code": "KAFKAS-MGMT-25",
"code": "CONNECTOR-MGMT-25",
"reason": "Resource gone"
},
{
"id": "30",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/30",
"code": "KAFKAS-MGMT-30",
"code": "CONNECTOR-MGMT-30",
"reason": "Provider not supported"
},
{
"id": "31",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/31",
"code": "KAFKAS-MGMT-31",
"code": "CONNECTOR-MGMT-31",
"reason": "Region not supported"
},
{
"id": "32",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/32",
"code": "KAFKAS-MGMT-32",
"code": "CONNECTOR-MGMT-32",
"reason": "Kafka cluster name is invalid"
},
{
"id": "33",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/33",
"code": "KAFKAS-MGMT-33",
"code": "CONNECTOR-MGMT-33",
"reason": "Minimum field length not reached"
},
{
"id": "34",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/34",
"code": "KAFKAS-MGMT-34",
"code": "CONNECTOR-MGMT-34",
"reason": "Maximum field length has been depassed"
},
{
"id": "35",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/35",
"code": "KAFKAS-MGMT-35",
"code": "CONNECTOR-MGMT-35",
"reason": "Only multiAZ Kafkas are supported, use multi_az=true"
},
{
"id": "36",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/36",
"code": "KAFKAS-MGMT-36",
"code": "CONNECTOR-MGMT-36",
"reason": "Kafka cluster name is already used"
},
{
"id": "37",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/37",
"code": "KAFKAS-MGMT-37",
"code": "CONNECTOR-MGMT-37",
"reason": "Field validation failed"
},
{
"id": "38",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/38",
"code": "KAFKAS-MGMT-38",
"code": "CONNECTOR-MGMT-38",
"reason": "Service account name is invalid"
},
{
"id": "39",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/39",
"code": "KAFKAS-MGMT-39",
"code": "CONNECTOR-MGMT-39",
"reason": "Service account desc is invalid"
},
{
"id": "40",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/40",
"code": "KAFKAS-MGMT-40",
"code": "CONNECTOR-MGMT-40",
"reason": "Service account id is invalid"
},
{
"id": "41",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/41",
"code": "KAFKAS-MGMT-41",
"code": "CONNECTOR-MGMT-41",
"reason": "Instance Type not supported"
},
{
"id": "103",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/103",
"code": "KAFKAS-MGMT-103",
"code": "CONNECTOR-MGMT-103",
"reason": "Synchronous action is not supported, use async=true parameter"
},
{
"id": "106",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/106",
"code": "KAFKAS-MGMT-106",
"code": "CONNECTOR-MGMT-106",
"reason": "Failed to create kafka client in the mas sso"
},
{
"id": "107",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/107",
"code": "KAFKAS-MGMT-107",
"code": "CONNECTOR-MGMT-107",
"reason": "Failed to get kafka client secret from the mas sso"
},
{
"id": "108",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/108",
"code": "KAFKAS-MGMT-108",
"code": "CONNECTOR-MGMT-108",
"reason": "Failed to get kafka client from the mas sso"
},
{
"id": "109",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/109",
"code": "KAFKAS-MGMT-109",
"code": "CONNECTOR-MGMT-109",
"reason": "Failed to delete kafka client from the mas sso"
},
{
"id": "110",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/110",
"code": "KAFKAS-MGMT-110",
"code": "CONNECTOR-MGMT-110",
"reason": "Failed to create service account"
},
{
"id": "111",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/111",
"code": "KAFKAS-MGMT-111",
"code": "CONNECTOR-MGMT-111",
"reason": "Failed to get service account"
},
{
"id": "112",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/112",
"code": "KAFKAS-MGMT-112",
"code": "CONNECTOR-MGMT-112",
"reason": "Failed to delete service account"
},
{
"id": "113",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/113",
"code": "KAFKAS-MGMT-113",
"code": "CONNECTOR-MGMT-113",
"reason": "Failed to find service account"
},
{
"id": "120",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/120",
"code": "KAFKAS-MGMT-120",
"code": "CONNECTOR-MGMT-120",
"reason": "Insufficient quota"
},
{
"id": "121",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/121",
"code": "KAFKAS-MGMT-121",
"code": "CONNECTOR-MGMT-121",
"reason": "Failed to check quota"
},
{
"id": "429",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/429",
"code": "KAFKAS-MGMT-429",
"code": "CONNECTOR-MGMT-429",
"reason": "Too Many requests"
},
{
"id": "1000",
"kind": "Error",
"href": "/api/kafkas_mgmt/v1/errors/1000",
"code": "KAFKAS-MGMT-1000",
"code": "CONNECTOR-MGMT-1000",
"reason": "An unexpected error happened, please check the log of the service for details"
}
]
Expand Down
6 changes: 3 additions & 3 deletions .errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
module.exports ={
kafkamgmt: {
definition: require("./errors_kafka_mgmt.json"),
file: "kafkamgmt/apiv1/errors.go"
file: "kafkamgmt/apiv1/error/errors.go"
},
registrymgmt: {
definition: require("./errors_srs_mgmt.json"),
file: "registrymgmt/apiv1/errors.go"
file: "registrymgmt/apiv1/error/errors.go"
},
connectormgmt: {
definition: require("./errors_connector_mgmt.json"),
file: "connectormgmt/apiv1/errors.go"
file: "connectormgmt/apiv1/error/errors.go"
},
}

9 changes: 7 additions & 2 deletions connectormgmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ connectors, _, err := client.DefaultApi.GetConnectors(ctx).Execute()
Checking specific error codes

```go
if connectormgmt.IsAPIError(err, connectormgmt.ERROR_4){
import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error"


if errors.IsAPIError(err, connectormgmt.ERROR_4){
// Do something
}
```

Obtaining API error

```go
apiError := connectormgmt.GetAPIError(err)
import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error"

apiError := errors.GetAPIError(err)
fmt.Println(apiError.Code)
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package connectormgmt
package error

import (
"errors"

connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"
)

// Code supplied by the API
type ServiceErrorCode string

// GetAPIError gets a strongly typed error from an error
func GetAPIError(err error) *connectormgmtclient.Error {
var openapiError connectormgmtclient.GenericOpenAPIError
Expand All @@ -27,7 +24,8 @@ func GetAPIError(err error) *connectormgmtclient.Error {
}

// IsAPIError returns true if the error contains the errCode
func IsAPIError(err error, code ServiceErrorCode) bool {
// Error code is an code that is returned by the API
func IsAPIError(err error, code string) bool {
mappedErr := GetAPIError(err)
if mappedErr == nil {
return false
Expand Down
Loading

0 comments on commit 8028992

Please sign in to comment.