diff --git a/examples/src/connector.ts b/examples/src/connector.ts index 2413d3f0..3e5533a2 100644 --- a/examples/src/connector.ts +++ b/examples/src/connector.ts @@ -1,5 +1,5 @@ // For released version replace with "@rhoas/connector-management-sdk" -import { Configuration, ConnectorsApi, APIErrorCodes } from "../../packages/connector-management-sdk"; +import { Configuration, ConnectorsApi, APIErrorCodes, isServiceApiError } from "../../packages/connector-management-sdk"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -14,7 +14,9 @@ const connectorsApi = new ConnectorsApi(apiConfig) connectorsApi.getConnector("id", "kafka-id").then((data) => { console.log(data?.data) }).catch((err) => { - console.error(err.message) - console.error("Validation issue", err.code == APIErrorCodes.ERROR_8) + if (isServiceApiError(err)) { + console.error("Validation issue", err.response?.data.code == APIErrorCodes.ERROR_8) + } + console.error(err) }) diff --git a/examples/src/kafka.ts b/examples/src/kafka.ts index 5b1df202..c8561c01 100644 --- a/examples/src/kafka.ts +++ b/examples/src/kafka.ts @@ -1,5 +1,5 @@ // For released version replace with "@rhoas/kafka-management-sdk" -import { Configuration, DefaultApi, APIErrorCodes } from "../../packages/kafka-management-sdk/dist"; +import { Configuration, DefaultApi, APIErrorCodes, isServiceApiError } from "../../packages/kafka-management-sdk/dist"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -14,7 +14,11 @@ const kafkaApi = new DefaultApi(apiConfig) kafkaApi.getKafkas().then((data) => { console.log(data?.data.items) }).catch((err) => { - console.error(err.message) - console.error("Validation issue", err.code == APIErrorCodes.ERROR_8) + if (isServiceApiError(err)) { + console.error("Validation issue", err.response?.data.code == APIErrorCodes.ERROR_8) + } + console.error(err) }) + + diff --git a/examples/src/serviceAccount.ts b/examples/src/serviceAccount.ts index 86790e2f..2f99ef93 100644 --- a/examples/src/serviceAccount.ts +++ b/examples/src/serviceAccount.ts @@ -14,6 +14,6 @@ serviceAccountAPI.getServiceAccounts().then((data) => { console.log(data?.data.items) }).catch((err) => { console.error(err.message) - console.error("Service account fail error", err.code == APIErrorCodes.ERROR_111) + console.error("Service account fail error", err.response?.data.code == APIErrorCodes.ERROR_111) }) diff --git a/examples/src/serviceRegistry.ts b/examples/src/serviceRegistry.ts index 53a9635b..b8c71405 100644 --- a/examples/src/serviceRegistry.ts +++ b/examples/src/serviceRegistry.ts @@ -1,4 +1,4 @@ -import { Configuration, RegistriesApi, APIErrorCodes } from "../../packages/registry-management-sdk/dist"; +import { Configuration, RegistriesApi, APIErrorCodes, isServiceApiError } from "../../packages/registry-management-sdk/dist"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -13,7 +13,9 @@ const registryApi = new RegistriesApi(apiConfig) registryApi.getRegistries().then((data) => { console.log(data?.data) }).catch((err) => { - console.error(err.message) - console.error("Invalid JSON format",err.code == APIErrorCodes.ERROR_5) + if (isServiceApiError(err)) { + console.error("Invalid JSON format", err.response?.data.code == APIErrorCodes.ERROR_5) + } + console.error(err) }) diff --git a/packages/connector-management-sdk/README.md b/packages/connector-management-sdk/README.md index db55cae9..23c4191c 100644 --- a/packages/connector-management-sdk/README.md +++ b/packages/connector-management-sdk/README.md @@ -13,7 +13,7 @@ npm install @rhoas/connector-management-sdk --save #### Usage ```ts -import { Configuration, ConnectorsApi, APIErrorCodes } from "@rhoas/connector-management-sdk"; +import { Configuration, ConnectorsApi, getErrorCode, isServiceApiError, APIErrorCodes } from "@rhoas/connector-management-sdk"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -28,8 +28,9 @@ const connectorsApi = new ConnectorsApi(apiConfig) connectorsApi.getConnector("id", "kafka-id").then((data) => { console.log(data?.data) }).catch((err) => { - console.error(err.message) - console.error("Validation issue", err.code == APIErrorCodes.ERROR_8) + if(isServiceApiError(err)){ + console.error("Validation issue", getErrorCode(err) == APIErrorCodes.ERROR_8) + } }) ``` diff --git a/packages/connector-management-sdk/src/errorHelpers.ts b/packages/connector-management-sdk/src/errorHelpers.ts new file mode 100644 index 00000000..a87d3d09 --- /dev/null +++ b/packages/connector-management-sdk/src/errorHelpers.ts @@ -0,0 +1,22 @@ +import { AxiosError } from "axios"; +import { ModelError } from "./generated"; + +/** + * Check if the error code originates from the API + * + * @param error generic error returned from fumction + * @returns true if error originated from the API + */ +export const isServiceApiError = (error: unknown): error is AxiosError => { + return (error as AxiosError).response?.data.code !== undefined; +}; + +/** + * Get the error code from the API error + * + * @param error generic error returned from fumction + * @returns error code (one of fields of APIErrorCodes) + */ +export const getErrorCode = (error: unknown): string | undefined => { + return (error as AxiosError).response?.data?.code; +}; \ No newline at end of file diff --git a/packages/connector-management-sdk/src/errors.ts b/packages/connector-management-sdk/src/errors.ts index 25aef065..5f6f29ed 100644 --- a/packages/connector-management-sdk/src/errors.ts +++ b/packages/connector-management-sdk/src/errors.ts @@ -6,131 +6,131 @@ apiCall.then((data) => { console.log(data?.data.items) }).catch((err) => { - if(APIErrorCodes.ERROR_5 == err.code) { + if(APIErrorCodes.ERROR_5 == err.response?.data.code) { // Handle error } }) ``` */ -export enum APIErrorCodes { +export const APIErrorCodes = { /** Forbidden to perform this action*/ - ERROR_4 = "KAFKAS-MGMT-4", + ERROR_4 : "KAFKAS-MGMT-4", /** Forbidden to create more instances than the maximum allowed*/ - ERROR_5 = "KAFKAS-MGMT-5", + ERROR_5 : "KAFKAS-MGMT-5", /** An entity with the specified unique values already exists*/ - ERROR_6 = "KAFKAS-MGMT-6", + ERROR_6 : "KAFKAS-MGMT-6", /** Resource not found*/ - ERROR_7 = "KAFKAS-MGMT-7", + ERROR_7 : "KAFKAS-MGMT-7", /** General validation failure*/ - ERROR_8 = "KAFKAS-MGMT-8", + ERROR_8 : "KAFKAS-MGMT-8", /** Unspecified error*/ - ERROR_9 = "KAFKAS-MGMT-9", + ERROR_9 : "KAFKAS-MGMT-9", /** HTTP Method not implemented for this endpoint*/ - ERROR_10 = "KAFKAS-MGMT-10", + ERROR_10 : "KAFKAS-MGMT-10", /** Account is unauthorized to perform this action*/ - ERROR_11 = "KAFKAS-MGMT-11", + ERROR_11 : "KAFKAS-MGMT-11", /** Required terms have not been accepted*/ - ERROR_12 = "KAFKAS-MGMT-12", + ERROR_12 : "KAFKAS-MGMT-12", /** Account authentication could not be verified*/ - ERROR_15 = "KAFKAS-MGMT-15", + ERROR_15 : "KAFKAS-MGMT-15", /** Unable to read request body*/ - ERROR_17 = "KAFKAS-MGMT-17", + ERROR_17 : "KAFKAS-MGMT-17", /** Bad request*/ - ERROR_21 = "KAFKAS-MGMT-21", + ERROR_21 : "KAFKAS-MGMT-21", /** Failed to parse search query*/ - ERROR_23 = "KAFKAS-MGMT-23", + ERROR_23 : "KAFKAS-MGMT-23", /** The maximum number of allowed kafka instances has been reached*/ - ERROR_24 = "KAFKAS-MGMT-24", + ERROR_24 : "KAFKAS-MGMT-24", /** Resource gone*/ - ERROR_25 = "KAFKAS-MGMT-25", + ERROR_25 : "KAFKAS-MGMT-25", /** Provider not supported*/ - ERROR_30 = "KAFKAS-MGMT-30", + ERROR_30 : "KAFKAS-MGMT-30", /** Region not supported*/ - ERROR_31 = "KAFKAS-MGMT-31", + ERROR_31 : "KAFKAS-MGMT-31", /** Kafka cluster name is invalid*/ - ERROR_32 = "KAFKAS-MGMT-32", + ERROR_32 : "KAFKAS-MGMT-32", /** Minimum field length not reached*/ - ERROR_33 = "KAFKAS-MGMT-33", + ERROR_33 : "KAFKAS-MGMT-33", /** Maximum field length has been depassed*/ - ERROR_34 = "KAFKAS-MGMT-34", + ERROR_34 : "KAFKAS-MGMT-34", /** Only multiAZ Kafkas are supported, use multi_az=true*/ - ERROR_35 = "KAFKAS-MGMT-35", + ERROR_35 : "KAFKAS-MGMT-35", /** Kafka cluster name is already used*/ - ERROR_36 = "KAFKAS-MGMT-36", + ERROR_36 : "KAFKAS-MGMT-36", /** Field validation failed*/ - ERROR_37 = "KAFKAS-MGMT-37", + ERROR_37 : "KAFKAS-MGMT-37", /** Service account name is invalid*/ - ERROR_38 = "KAFKAS-MGMT-38", + ERROR_38 : "KAFKAS-MGMT-38", /** Service account desc is invalid*/ - ERROR_39 = "KAFKAS-MGMT-39", + ERROR_39 : "KAFKAS-MGMT-39", /** Service account id is invalid*/ - ERROR_40 = "KAFKAS-MGMT-40", + ERROR_40 : "KAFKAS-MGMT-40", /** Instance Type not supported*/ - ERROR_41 = "KAFKAS-MGMT-41", + ERROR_41 : "KAFKAS-MGMT-41", /** Synchronous action is not supported, use async=true parameter*/ - ERROR_103 = "KAFKAS-MGMT-103", + ERROR_103 : "KAFKAS-MGMT-103", /** Failed to create kafka client in the mas sso*/ - ERROR_106 = "KAFKAS-MGMT-106", + ERROR_106 : "KAFKAS-MGMT-106", /** Failed to get kafka client secret from the mas sso*/ - ERROR_107 = "KAFKAS-MGMT-107", + ERROR_107 : "KAFKAS-MGMT-107", /** Failed to get kafka client from the mas sso*/ - ERROR_108 = "KAFKAS-MGMT-108", + ERROR_108 : "KAFKAS-MGMT-108", /** Failed to delete kafka client from the mas sso*/ - ERROR_109 = "KAFKAS-MGMT-109", + ERROR_109 : "KAFKAS-MGMT-109", /** Failed to create service account*/ - ERROR_110 = "KAFKAS-MGMT-110", + ERROR_110 : "KAFKAS-MGMT-110", /** Failed to get service account*/ - ERROR_111 = "KAFKAS-MGMT-111", + ERROR_111 : "KAFKAS-MGMT-111", /** Failed to delete service account*/ - ERROR_112 = "KAFKAS-MGMT-112", + ERROR_112 : "KAFKAS-MGMT-112", /** Failed to find service account*/ - ERROR_113 = "KAFKAS-MGMT-113", + ERROR_113 : "KAFKAS-MGMT-113", /** Insufficient quota*/ - ERROR_120 = "KAFKAS-MGMT-120", + ERROR_120 : "KAFKAS-MGMT-120", /** Failed to check quota*/ - ERROR_121 = "KAFKAS-MGMT-121", + ERROR_121 : "KAFKAS-MGMT-121", /** Too Many requests*/ - ERROR_429 = "KAFKAS-MGMT-429", + ERROR_429 : "KAFKAS-MGMT-429", /** An unexpected error happened, please check the log of the service for details*/ - ERROR_1000 = "KAFKAS-MGMT-1000", + ERROR_1000 : "KAFKAS-MGMT-1000", } \ No newline at end of file diff --git a/packages/connector-management-sdk/src/index.ts b/packages/connector-management-sdk/src/index.ts index 9a8c26fb..18a4cca4 100644 --- a/packages/connector-management-sdk/src/index.ts +++ b/packages/connector-management-sdk/src/index.ts @@ -1,2 +1,3 @@ export * from "./generated"; -export * from "./errors"; \ No newline at end of file +export * from "./errors"; +export * from "./errorHelpers"; \ No newline at end of file diff --git a/packages/kafka-management-sdk/README.md b/packages/kafka-management-sdk/README.md index f3278c8d..decaaa49 100644 --- a/packages/kafka-management-sdk/README.md +++ b/packages/kafka-management-sdk/README.md @@ -13,7 +13,7 @@ npm install @rhoas/kafka-management-sdk --save #### Usage ```ts -import { Configuration, DefaultApi, APIErrorCodes } from "@rhoas/kafka-management-sdk"; +import { Configuration, DefaultApi, getErrorCode, isServiceApiError, APIErrorCodes } from "@rhoas/kafka-management-sdk"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -31,8 +31,9 @@ kafkaApi console.log(data?.data.items); }) .catch((err) => { - console.error(err.message); - console.error("Validation issue", err.code == APIErrorCodes.ERROR_8) + if(isServiceApiError(err)){ + console.error("Validation issue", getErrorCode(err) == APIErrorCodes.ERROR_8) + } }); ``` diff --git a/packages/kafka-management-sdk/src/errorHelpers.ts b/packages/kafka-management-sdk/src/errorHelpers.ts new file mode 100644 index 00000000..a87d3d09 --- /dev/null +++ b/packages/kafka-management-sdk/src/errorHelpers.ts @@ -0,0 +1,22 @@ +import { AxiosError } from "axios"; +import { ModelError } from "./generated"; + +/** + * Check if the error code originates from the API + * + * @param error generic error returned from fumction + * @returns true if error originated from the API + */ +export const isServiceApiError = (error: unknown): error is AxiosError => { + return (error as AxiosError).response?.data.code !== undefined; +}; + +/** + * Get the error code from the API error + * + * @param error generic error returned from fumction + * @returns error code (one of fields of APIErrorCodes) + */ +export const getErrorCode = (error: unknown): string | undefined => { + return (error as AxiosError).response?.data?.code; +}; \ No newline at end of file diff --git a/packages/kafka-management-sdk/src/errors.ts b/packages/kafka-management-sdk/src/errors.ts index 4e140f2b..45a09f6f 100644 --- a/packages/kafka-management-sdk/src/errors.ts +++ b/packages/kafka-management-sdk/src/errors.ts @@ -6,131 +6,131 @@ apiCall.then((data) => { console.log(data?.data.items) }).catch((err) => { - if(APIErrorCodes.ERROR_5 == err.code) { + if(APIErrorCodes.ERROR_5 == err.response?.data.code) { // Handle error } }) ``` */ -export enum APIErrorCodes { +export const APIErrorCodes = { /** Forbidden to perform this action*/ - ERROR_4 = "KAFKAS-MGMT-4", + ERROR_4 : "KAFKAS-MGMT-4", /** Forbidden to create more instances than the maximum allowed*/ - ERROR_5 = "KAFKAS-MGMT-5", + ERROR_5 : "KAFKAS-MGMT-5", /** An entity with the specified unique values already exists*/ - ERROR_6 = "KAFKAS-MGMT-6", + ERROR_6 : "KAFKAS-MGMT-6", /** Resource not found*/ - ERROR_7 = "KAFKAS-MGMT-7", + ERROR_7 : "KAFKAS-MGMT-7", /** General validation failure*/ - ERROR_8 = "KAFKAS-MGMT-8", + ERROR_8 : "KAFKAS-MGMT-8", /** Unspecified error*/ - ERROR_9 = "KAFKAS-MGMT-9", + ERROR_9 : "KAFKAS-MGMT-9", /** HTTP Method not implemented for this endpoint*/ - ERROR_10 = "KAFKAS-MGMT-10", + ERROR_10 : "KAFKAS-MGMT-10", /** Account is unauthorized to perform this action*/ - ERROR_11 = "KAFKAS-MGMT-11", + ERROR_11 : "KAFKAS-MGMT-11", /** Required terms have not been accepted*/ - ERROR_12 = "KAFKAS-MGMT-12", + ERROR_12 : "KAFKAS-MGMT-12", /** Account authentication could not be verified*/ - ERROR_15 = "KAFKAS-MGMT-15", + ERROR_15 : "KAFKAS-MGMT-15", /** Unable to read request body*/ - ERROR_17 = "KAFKAS-MGMT-17", + ERROR_17 : "KAFKAS-MGMT-17", /** Bad request*/ - ERROR_21 = "KAFKAS-MGMT-21", + ERROR_21 : "KAFKAS-MGMT-21", /** Failed to parse search query*/ - ERROR_23 = "KAFKAS-MGMT-23", + ERROR_23 : "KAFKAS-MGMT-23", /** The maximum number of allowed kafka instances has been reached*/ - ERROR_24 = "KAFKAS-MGMT-24", + ERROR_24 : "KAFKAS-MGMT-24", /** Resource gone*/ - ERROR_25 = "KAFKAS-MGMT-25", + ERROR_25 : "KAFKAS-MGMT-25", /** Provider not supported*/ - ERROR_30 = "KAFKAS-MGMT-30", + ERROR_30 : "KAFKAS-MGMT-30", /** Region not supported*/ - ERROR_31 = "KAFKAS-MGMT-31", + ERROR_31 : "KAFKAS-MGMT-31", /** Kafka cluster name is invalid*/ - ERROR_32 = "KAFKAS-MGMT-32", + ERROR_32 : "KAFKAS-MGMT-32", /** Minimum field length not reached*/ - ERROR_33 = "KAFKAS-MGMT-33", + ERROR_33 : "KAFKAS-MGMT-33", /** Maximum field length has been depassed*/ - ERROR_34 = "KAFKAS-MGMT-34", + ERROR_34 : "KAFKAS-MGMT-34", /** Only multiAZ Kafkas are supported, use multi_az=true*/ - ERROR_35 = "KAFKAS-MGMT-35", + ERROR_35 : "KAFKAS-MGMT-35", /** Kafka cluster name is already used*/ - ERROR_36 = "KAFKAS-MGMT-36", + ERROR_36 : "KAFKAS-MGMT-36", /** Field validation failed*/ - ERROR_37 = "KAFKAS-MGMT-37", + ERROR_37 : "KAFKAS-MGMT-37", /** Service account name is invalid*/ - ERROR_38 = "KAFKAS-MGMT-38", + ERROR_38 : "KAFKAS-MGMT-38", /** Service account desc is invalid*/ - ERROR_39 = "KAFKAS-MGMT-39", + ERROR_39 : "KAFKAS-MGMT-39", /** Service account id is invalid*/ - ERROR_40 = "KAFKAS-MGMT-40", + ERROR_40 : "KAFKAS-MGMT-40", /** Instance Type not supported*/ - ERROR_41 = "KAFKAS-MGMT-41", + ERROR_41 : "KAFKAS-MGMT-41", /** Synchronous action is not supported, use async=true parameter*/ - ERROR_103 = "KAFKAS-MGMT-103", + ERROR_103 : "KAFKAS-MGMT-103", /** Failed to create kafka client in the mas sso*/ - ERROR_106 = "KAFKAS-MGMT-106", + ERROR_106 : "KAFKAS-MGMT-106", /** Failed to get kafka client secret from the mas sso*/ - ERROR_107 = "KAFKAS-MGMT-107", + ERROR_107 : "KAFKAS-MGMT-107", /** Failed to get kafka client from the mas sso*/ - ERROR_108 = "KAFKAS-MGMT-108", + ERROR_108 : "KAFKAS-MGMT-108", /** Failed to delete kafka client from the mas sso*/ - ERROR_109 = "KAFKAS-MGMT-109", + ERROR_109 : "KAFKAS-MGMT-109", /** Failed to create service account*/ - ERROR_110 = "KAFKAS-MGMT-110", + ERROR_110 : "KAFKAS-MGMT-110", /** Failed to get service account*/ - ERROR_111 = "KAFKAS-MGMT-111", + ERROR_111 : "KAFKAS-MGMT-111", /** Failed to delete service account*/ - ERROR_112 = "KAFKAS-MGMT-112", + ERROR_112 : "KAFKAS-MGMT-112", /** Failed to find service account*/ - ERROR_113 = "KAFKAS-MGMT-113", + ERROR_113 : "KAFKAS-MGMT-113", /** Insufficient quota*/ - ERROR_120 = "KAFKAS-MGMT-120", + ERROR_120 : "KAFKAS-MGMT-120", /** Failed to check quota*/ - ERROR_121 = "KAFKAS-MGMT-121", + ERROR_121 : "KAFKAS-MGMT-121", /** Too Many requests*/ - ERROR_429 = "KAFKAS-MGMT-429", + ERROR_429 : "KAFKAS-MGMT-429", /** An unexpected error happened, please check the log of the service for details*/ - ERROR_1000 = "KAFKAS-MGMT-1000", + ERROR_1000 : "KAFKAS-MGMT-1000", } \ No newline at end of file diff --git a/packages/kafka-management-sdk/src/index.ts b/packages/kafka-management-sdk/src/index.ts index 1b250c37..0b6717c3 100644 --- a/packages/kafka-management-sdk/src/index.ts +++ b/packages/kafka-management-sdk/src/index.ts @@ -1,3 +1,4 @@ // Export generated API export * from "./generated" -export * from "./errors"; \ No newline at end of file +export * from "./errors"; +export * from "./errorHelpers"; \ No newline at end of file diff --git a/packages/registry-management-sdk/README.md b/packages/registry-management-sdk/README.md index 103a8364..a92aebbc 100644 --- a/packages/registry-management-sdk/README.md +++ b/packages/registry-management-sdk/README.md @@ -13,7 +13,7 @@ npm install @rhoas/registry-management-sdk --save #### Usage ```ts -import { Configuration, DefaultApi, APIErrorCodes } from "@rhoas/registry-management-sdk"; +import { Configuration, DefaultApi, getErrorCode, isServiceApiError, APIErrorCodes } from "@rhoas/registry-management-sdk"; const accessToken = process.env.CLOUD_API_TOKEN; const basePath = "https://api.openshift.com"; @@ -28,8 +28,10 @@ const registryApi = new DefaultApi(apiConfig) registryApi.getRegistries().then((data) => { console.log(data?.data) }).catch((err) => { - console.error(err.message) - console.error("Invalid JSON format",err.code == APIErrorCodes.ERROR_5) + if(isServiceApiError(err)){ + console.error("Invalid JSON format", getErrorCode(err) == APIErrorCodes.ERROR_5) + } + }) ``` diff --git a/packages/registry-management-sdk/src/errorHelpers.ts b/packages/registry-management-sdk/src/errorHelpers.ts new file mode 100644 index 00000000..a87d3d09 --- /dev/null +++ b/packages/registry-management-sdk/src/errorHelpers.ts @@ -0,0 +1,22 @@ +import { AxiosError } from "axios"; +import { ModelError } from "./generated"; + +/** + * Check if the error code originates from the API + * + * @param error generic error returned from fumction + * @returns true if error originated from the API + */ +export const isServiceApiError = (error: unknown): error is AxiosError => { + return (error as AxiosError).response?.data.code !== undefined; +}; + +/** + * Get the error code from the API error + * + * @param error generic error returned from fumction + * @returns error code (one of fields of APIErrorCodes) + */ +export const getErrorCode = (error: unknown): string | undefined => { + return (error as AxiosError).response?.data?.code; +}; \ No newline at end of file diff --git a/packages/registry-management-sdk/src/errors.ts b/packages/registry-management-sdk/src/errors.ts index b614d762..6184b384 100644 --- a/packages/registry-management-sdk/src/errors.ts +++ b/packages/registry-management-sdk/src/errors.ts @@ -6,41 +6,41 @@ apiCall.then((data) => { console.log(data?.data.items) }).catch((err) => { - if(APIErrorCodes.ERROR_5 == err.code) { + if(APIErrorCodes.ERROR_5 == err.response?.data.code) { // Handle error } }) ``` */ -export enum APIErrorCodes { +export const APIErrorCodes = { /** Unspecified error*/ - ERROR_1 = "SRS-MGMT-1", + ERROR_1 : "SRS-MGMT-1", /** Registry with id='?' not found*/ - ERROR_2 = "SRS-MGMT-2", + ERROR_2 : "SRS-MGMT-2", /** Bad date or time format*/ - ERROR_3 = "SRS-MGMT-3", + ERROR_3 : "SRS-MGMT-3", /** Invalid request content. Make sure the request conforms to the given JSON schema*/ - ERROR_4 = "SRS-MGMT-4", + ERROR_4 : "SRS-MGMT-4", /** Bad request format - invalid JSON*/ - ERROR_5 = "SRS-MGMT-5", + ERROR_5 : "SRS-MGMT-5", /** Required terms have not been accepted for account id='?'*/ - ERROR_6 = "SRS-MGMT-6", + ERROR_6 : "SRS-MGMT-6", /** The maximum number of allowed Registry instances has been reached*/ - ERROR_7 = "SRS-MGMT-7", + ERROR_7 : "SRS-MGMT-7", /** Error type with id='?' not found*/ - ERROR_8 = "SRS-MGMT-8", + ERROR_8 : "SRS-MGMT-8", /** Data conflict. Make sure a Registry with the given name does not already exist*/ - ERROR_9 = "SRS-MGMT-9", + ERROR_9 : "SRS-MGMT-9", /** Bad request format - unsupported media type*/ - ERROR_10 = "SRS-MGMT-10", + ERROR_10 : "SRS-MGMT-10", } \ No newline at end of file diff --git a/packages/registry-management-sdk/src/index.ts b/packages/registry-management-sdk/src/index.ts index 1b250c37..0b6717c3 100644 --- a/packages/registry-management-sdk/src/index.ts +++ b/packages/registry-management-sdk/src/index.ts @@ -1,3 +1,4 @@ // Export generated API export * from "./generated" -export * from "./errors"; \ No newline at end of file +export * from "./errors"; +export * from "./errorHelpers"; \ No newline at end of file diff --git a/scripts/errors/generate-errors.js b/scripts/errors/generate-errors.js index dd4a29fc..c0e03f0c 100755 --- a/scripts/errors/generate-errors.js +++ b/scripts/errors/generate-errors.js @@ -22,18 +22,18 @@ for (api in apis) { apiCall.then((data) => { console.log(data?.data.items) }).catch((err) => { - if(APIErrorCodes.ERROR_5 == err.code) { + if(APIErrorCodes.ERROR_5 == err.response?.data.code) { // Handle error } }) \`\`\` */ -export enum APIErrorCodes { +export const APIErrorCodes = { `; apiJson.items.forEach(function (errorType) { stringBuffer += ` /** ${errorType.reason}*/\n`; - stringBuffer += ` ERROR_${errorType.id} = "${errorType.code}", \n\n`; + stringBuffer += ` ERROR_${errorType.id} : "${errorType.code}", \n\n`; }); stringBuffer += `}`;