diff --git a/.errors/errors_connector_mgmt.json b/.errors/errors_connector_mgmt.json index eb5f4813..c5cb54e2 100644 --- a/.errors/errors_connector_mgmt.json +++ b/.errors/errors_connector_mgmt.json @@ -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" } ] diff --git a/.errors/index.js b/.errors/index.js index 080f4d17..cb613f1e 100644 --- a/.errors/index.js +++ b/.errors/index.js @@ -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" }, } diff --git a/connectormgmt/README.md b/connectormgmt/README.md index 4614f892..c5335d3f 100644 --- a/connectormgmt/README.md +++ b/connectormgmt/README.md @@ -74,7 +74,10 @@ 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 } ``` @@ -82,7 +85,9 @@ if connectormgmt.IsAPIError(err, connectormgmt.ERROR_4){ 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) ``` diff --git a/connectormgmt/apiv1/error_sdk.go b/connectormgmt/apiv1/error/error_sdk.go similarity index 83% rename from connectormgmt/apiv1/error_sdk.go rename to connectormgmt/apiv1/error/error_sdk.go index 8be96e76..95567b52 100644 --- a/connectormgmt/apiv1/error_sdk.go +++ b/connectormgmt/apiv1/error/error_sdk.go @@ -1,4 +1,4 @@ -package connectormgmt +package error import ( "errors" @@ -6,9 +6,6 @@ import ( 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 @@ -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 diff --git a/connectormgmt/apiv1/error/errors.go b/connectormgmt/apiv1/error/errors.go new file mode 100644 index 00000000..8518e4c8 --- /dev/null +++ b/connectormgmt/apiv1/error/errors.go @@ -0,0 +1,129 @@ + +package error + +// connectormgmt error codes +type ErrorCode string + +const ( + + // Forbidden to perform this action + ERROR_4 ErrorCode = "CONNECTOR-MGMT-4" + + // Forbidden to create more instances than the maximum allowed + ERROR_5 ErrorCode = "CONNECTOR-MGMT-5" + + // An entity with the specified unique values already exists + ERROR_6 ErrorCode = "CONNECTOR-MGMT-6" + + // Resource not found + ERROR_7 ErrorCode = "CONNECTOR-MGMT-7" + + // General validation failure + ERROR_8 ErrorCode = "CONNECTOR-MGMT-8" + + // Unspecified error + ERROR_9 ErrorCode = "CONNECTOR-MGMT-9" + + // HTTP Method not implemented for this endpoint + ERROR_10 ErrorCode = "CONNECTOR-MGMT-10" + + // Account is unauthorized to perform this action + ERROR_11 ErrorCode = "CONNECTOR-MGMT-11" + + // Required terms have not been accepted + ERROR_12 ErrorCode = "CONNECTOR-MGMT-12" + + // Account authentication could not be verified + ERROR_15 ErrorCode = "CONNECTOR-MGMT-15" + + // Unable to read request body + ERROR_17 ErrorCode = "CONNECTOR-MGMT-17" + + // Bad request + ERROR_21 ErrorCode = "CONNECTOR-MGMT-21" + + // Failed to parse search query + ERROR_23 ErrorCode = "CONNECTOR-MGMT-23" + + // The maximum number of allowed kafka instances has been reached + ERROR_24 ErrorCode = "CONNECTOR-MGMT-24" + + // Resource gone + ERROR_25 ErrorCode = "CONNECTOR-MGMT-25" + + // Provider not supported + ERROR_30 ErrorCode = "CONNECTOR-MGMT-30" + + // Region not supported + ERROR_31 ErrorCode = "CONNECTOR-MGMT-31" + + // Kafka cluster name is invalid + ERROR_32 ErrorCode = "CONNECTOR-MGMT-32" + + // Minimum field length not reached + ERROR_33 ErrorCode = "CONNECTOR-MGMT-33" + + // Maximum field length has been depassed + ERROR_34 ErrorCode = "CONNECTOR-MGMT-34" + + // Only multiAZ Kafkas are supported, use multi_az=true + ERROR_35 ErrorCode = "CONNECTOR-MGMT-35" + + // Kafka cluster name is already used + ERROR_36 ErrorCode = "CONNECTOR-MGMT-36" + + // Field validation failed + ERROR_37 ErrorCode = "CONNECTOR-MGMT-37" + + // Service account name is invalid + ERROR_38 ErrorCode = "CONNECTOR-MGMT-38" + + // Service account desc is invalid + ERROR_39 ErrorCode = "CONNECTOR-MGMT-39" + + // Service account id is invalid + ERROR_40 ErrorCode = "CONNECTOR-MGMT-40" + + // Instance Type not supported + ERROR_41 ErrorCode = "CONNECTOR-MGMT-41" + + // Synchronous action is not supported, use async=true parameter + ERROR_103 ErrorCode = "CONNECTOR-MGMT-103" + + // Failed to create kafka client in the mas sso + ERROR_106 ErrorCode = "CONNECTOR-MGMT-106" + + // Failed to get kafka client secret from the mas sso + ERROR_107 ErrorCode = "CONNECTOR-MGMT-107" + + // Failed to get kafka client from the mas sso + ERROR_108 ErrorCode = "CONNECTOR-MGMT-108" + + // Failed to delete kafka client from the mas sso + ERROR_109 ErrorCode = "CONNECTOR-MGMT-109" + + // Failed to create service account + ERROR_110 ErrorCode = "CONNECTOR-MGMT-110" + + // Failed to get service account + ERROR_111 ErrorCode = "CONNECTOR-MGMT-111" + + // Failed to delete service account + ERROR_112 ErrorCode = "CONNECTOR-MGMT-112" + + // Failed to find service account + ERROR_113 ErrorCode = "CONNECTOR-MGMT-113" + + // Insufficient quota + ERROR_120 ErrorCode = "CONNECTOR-MGMT-120" + + // Failed to check quota + ERROR_121 ErrorCode = "CONNECTOR-MGMT-121" + + // Too Many requests + ERROR_429 ErrorCode = "CONNECTOR-MGMT-429" + + // An unexpected error happened, please check the log of the service for details + ERROR_1000 ErrorCode = "CONNECTOR-MGMT-1000" + +) \ No newline at end of file diff --git a/connectormgmt/apiv1/errors.go b/connectormgmt/apiv1/errors.go deleted file mode 100644 index e4b5cc5c..00000000 --- a/connectormgmt/apiv1/errors.go +++ /dev/null @@ -1,129 +0,0 @@ - -package connectormgmt - -// connectormgmt error codes -type ErrorCode string - -const ( - - // Forbidden to perform this action - ERROR_4 ErrorCode = "KAFKAS-MGMT-4" - - // Forbidden to create more instances than the maximum allowed - ERROR_5 ErrorCode = "KAFKAS-MGMT-5" - - // An entity with the specified unique values already exists - ERROR_6 ErrorCode = "KAFKAS-MGMT-6" - - // Resource not found - ERROR_7 ErrorCode = "KAFKAS-MGMT-7" - - // General validation failure - ERROR_8 ErrorCode = "KAFKAS-MGMT-8" - - // Unspecified error - ERROR_9 ErrorCode = "KAFKAS-MGMT-9" - - // HTTP Method not implemented for this endpoint - ERROR_10 ErrorCode = "KAFKAS-MGMT-10" - - // Account is unauthorized to perform this action - ERROR_11 ErrorCode = "KAFKAS-MGMT-11" - - // Required terms have not been accepted - ERROR_12 ErrorCode = "KAFKAS-MGMT-12" - - // Account authentication could not be verified - ERROR_15 ErrorCode = "KAFKAS-MGMT-15" - - // Unable to read request body - ERROR_17 ErrorCode = "KAFKAS-MGMT-17" - - // Bad request - ERROR_21 ErrorCode = "KAFKAS-MGMT-21" - - // Failed to parse search query - ERROR_23 ErrorCode = "KAFKAS-MGMT-23" - - // The maximum number of allowed kafka instances has been reached - ERROR_24 ErrorCode = "KAFKAS-MGMT-24" - - // Resource gone - ERROR_25 ErrorCode = "KAFKAS-MGMT-25" - - // Provider not supported - ERROR_30 ErrorCode = "KAFKAS-MGMT-30" - - // Region not supported - ERROR_31 ErrorCode = "KAFKAS-MGMT-31" - - // Kafka cluster name is invalid - ERROR_32 ErrorCode = "KAFKAS-MGMT-32" - - // Minimum field length not reached - ERROR_33 ErrorCode = "KAFKAS-MGMT-33" - - // Maximum field length has been depassed - ERROR_34 ErrorCode = "KAFKAS-MGMT-34" - - // Only multiAZ Kafkas are supported, use multi_az=true - ERROR_35 ErrorCode = "KAFKAS-MGMT-35" - - // Kafka cluster name is already used - ERROR_36 ErrorCode = "KAFKAS-MGMT-36" - - // Field validation failed - ERROR_37 ErrorCode = "KAFKAS-MGMT-37" - - // Service account name is invalid - ERROR_38 ErrorCode = "KAFKAS-MGMT-38" - - // Service account desc is invalid - ERROR_39 ErrorCode = "KAFKAS-MGMT-39" - - // Service account id is invalid - ERROR_40 ErrorCode = "KAFKAS-MGMT-40" - - // Instance Type not supported - ERROR_41 ErrorCode = "KAFKAS-MGMT-41" - - // Synchronous action is not supported, use async=true parameter - ERROR_103 ErrorCode = "KAFKAS-MGMT-103" - - // Failed to create kafka client in the mas sso - ERROR_106 ErrorCode = "KAFKAS-MGMT-106" - - // Failed to get kafka client secret from the mas sso - ERROR_107 ErrorCode = "KAFKAS-MGMT-107" - - // Failed to get kafka client from the mas sso - ERROR_108 ErrorCode = "KAFKAS-MGMT-108" - - // Failed to delete kafka client from the mas sso - ERROR_109 ErrorCode = "KAFKAS-MGMT-109" - - // Failed to create service account - ERROR_110 ErrorCode = "KAFKAS-MGMT-110" - - // Failed to get service account - ERROR_111 ErrorCode = "KAFKAS-MGMT-111" - - // Failed to delete service account - ERROR_112 ErrorCode = "KAFKAS-MGMT-112" - - // Failed to find service account - ERROR_113 ErrorCode = "KAFKAS-MGMT-113" - - // Insufficient quota - ERROR_120 ErrorCode = "KAFKAS-MGMT-120" - - // Failed to check quota - ERROR_121 ErrorCode = "KAFKAS-MGMT-121" - - // Too Many requests - ERROR_429 ErrorCode = "KAFKAS-MGMT-429" - - // An unexpected error happened, please check the log of the service for details - ERROR_1000 ErrorCode = "KAFKAS-MGMT-1000" - -) \ No newline at end of file diff --git a/kafkamgmt/README.md b/kafkamgmt/README.md index c5e840ec..fae230f6 100644 --- a/kafkamgmt/README.md +++ b/kafkamgmt/README.md @@ -74,7 +74,9 @@ kafkas, _, err := client.DefaultApi.GetKafkas(ctx).Execute() Checking specific error codes ```go -if kafkamgmt.IsAPIError(err, kafkamgmt.ERROR_4){ +import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error" + +if errors.IsAPIError(err, kafkamgmt.ERROR_4){ // Do something } ``` @@ -82,7 +84,9 @@ if kafkamgmt.IsAPIError(err, kafkamgmt.ERROR_4){ Obtaining API error ```go -apiError := kafkamgmt.GetAPIError(err) +import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error" + +apiError := errors.GetAPIError(err) fmt.Println(apiError.Code) ``` diff --git a/kafkamgmt/apiv1/error_sdk.go b/kafkamgmt/apiv1/error/error_sdk.go similarity index 83% rename from kafkamgmt/apiv1/error_sdk.go rename to kafkamgmt/apiv1/error/error_sdk.go index fcfeb828..b6df77eb 100644 --- a/kafkamgmt/apiv1/error_sdk.go +++ b/kafkamgmt/apiv1/error/error_sdk.go @@ -1,4 +1,4 @@ -package kafkamgmt +package error import ( "errors" @@ -6,9 +6,6 @@ import ( kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" ) -// Code supplied by the API -type ServiceErrorCode string - // GetAPIError gets a strongly typed error from an error func GetAPIError(err error) *kafkamgmtclient.Error { var openapiError kafkamgmtclient.GenericOpenAPIError @@ -27,7 +24,7 @@ func GetAPIError(err error) *kafkamgmtclient.Error { } // IsAPIError returns true if the error contains the errCode -func IsAPIError(err error, code ServiceErrorCode) bool { +func IsAPIError(err error, code string) bool { mappedErr := GetAPIError(err) if mappedErr == nil { return false diff --git a/kafkamgmt/apiv1/errors.go b/kafkamgmt/apiv1/error/errors.go similarity index 99% rename from kafkamgmt/apiv1/errors.go rename to kafkamgmt/apiv1/error/errors.go index a8cc7a23..4248d039 100644 --- a/kafkamgmt/apiv1/errors.go +++ b/kafkamgmt/apiv1/error/errors.go @@ -1,5 +1,5 @@ -package kafkamgmt +package error // kafkamgmt error codes type ErrorCode string diff --git a/registrymgmt/README.md b/registrymgmt/README.md index acc81692..ab337446 100644 --- a/registrymgmt/README.md +++ b/registrymgmt/README.md @@ -74,7 +74,9 @@ registries, _, err := client.RegistriesApi.GetRegistries(ctx).Execute() Checking specific error codes ```go -if registrymgmt.IsAPIError(err, registrymgmt.ERROR_4){ +import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error" + +if errors.IsAPIError(err, registrymgmt.ERROR_4){ // Do something } ``` @@ -82,7 +84,9 @@ if registrymgmt.IsAPIError(err, registrymgmt.ERROR_4){ Obtaining API error ```go -apiError := registrymgmt.GetAPIError(err) +import "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error" + +apiError := errors.GetAPIError(err) fmt.Println(apiError.Code) ``` diff --git a/registrymgmt/apiv1/error_sdk.go b/registrymgmt/apiv1/error/error_sdk.go similarity index 83% rename from registrymgmt/apiv1/error_sdk.go rename to registrymgmt/apiv1/error/error_sdk.go index 7cdc8a30..d6e11ee2 100644 --- a/registrymgmt/apiv1/error_sdk.go +++ b/registrymgmt/apiv1/error/error_sdk.go @@ -1,4 +1,4 @@ -package registrymgmt +package error import ( "errors" @@ -6,9 +6,6 @@ import ( registrymgmtclient "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) *registrymgmtclient.Error { var openapiError registrymgmtclient.GenericOpenAPIError @@ -27,7 +24,7 @@ func GetAPIError(err error) *registrymgmtclient.Error { } // IsAPIError returns true if the error contains the errCode -func IsAPIError(err error, code ServiceErrorCode) bool { +func IsAPIError(err error, code string) bool { mappedErr := GetAPIError(err) if mappedErr == nil { return false diff --git a/registrymgmt/apiv1/errors.go b/registrymgmt/apiv1/error/errors.go similarity index 97% rename from registrymgmt/apiv1/errors.go rename to registrymgmt/apiv1/error/errors.go index 54e29ee0..ead9a0d9 100644 --- a/registrymgmt/apiv1/errors.go +++ b/registrymgmt/apiv1/error/errors.go @@ -1,5 +1,5 @@ -package registrymgmt +package error // registrymgmt error codes type ErrorCode string diff --git a/scripts/errors/generate-errors.js b/scripts/errors/generate-errors.js index aa2fd866..7a20ccbd 100755 --- a/scripts/errors/generate-errors.js +++ b/scripts/errors/generate-errors.js @@ -15,7 +15,7 @@ for (api in apis) { } stringBuffer=` -package ${api} +package error // ${api} error codes type ErrorCode string