diff --git a/src/services/version-control-system-integration-services/post-callback-url-service.js b/src/services/version-control-system-integration-services/post-callback-url-service.js index fc49e47cd..b10da675d 100644 --- a/src/services/version-control-system-integration-services/post-callback-url-service.js +++ b/src/services/version-control-system-integration-services/post-callback-url-service.js @@ -1,6 +1,7 @@ -import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter' +import { AxiosHttpClientAdapter } from '../axios/AxiosHttpClientAdapter' import { makeVersionControlSystemBaseUrl } from './make-version-control-system-base-url' - +import * as Errors from '@/services/axios/errors' +import { extractApiError } from '@/helpers/extract-api-error' export const postCallbackUrlService = async (path, body) => { let httpResponse = await AxiosHttpClientAdapter.request({ url: `${makeVersionControlSystemBaseUrl()}${path}`, @@ -10,3 +11,19 @@ export const postCallbackUrlService = async (path, body) => { return parseHttpResponse(httpResponse) } + +/** + * @param {Object} httpResponse - The HTTP response object. + * @param {Object} httpResponse.body - The response body. + * @returns {string} The formatted error message. + */ +const parseHttpResponse = (httpResponse) => { + switch (httpResponse.statusCode) { + case 200: + return { feedback: 'Git Hub Installation successfully completed' } + case 500: + throw new Errors.InternalServerError().message + default: + throw new Error(extractApiError(httpResponse)).message + } +} diff --git a/src/templates/template-engine-block/index.vue b/src/templates/template-engine-block/index.vue index e6259dfd1..c25722989 100644 --- a/src/templates/template-engine-block/index.vue +++ b/src/templates/template-engine-block/index.vue @@ -360,8 +360,18 @@ const saveIntegration = async (integration) => { isIntegrationsLoading.value = true - await props.postCallbackUrlService(callbackUrl.value, integration.data) - await listIntegrations() + try { + await props.postCallbackUrlService(callbackUrl.value, integration.data) + } catch (error) { + toast.add({ + closable: true, + severity: 'error', + summary: 'error', + detail: error + }) + } finally { + await listIntegrations() + } } const createSchemaObject = async () => {