From b8f8df5f48f3e53de4f435e30db35b50eaae05a0 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Wed, 28 Feb 2018 07:52:40 +0100 Subject: [PATCH] fix(endpoints-creation): remove endpoint if an error is raised during creation (#1678) --- app/portainer/views/endpoints/endpointsController.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/portainer/views/endpoints/endpointsController.js b/app/portainer/views/endpoints/endpointsController.js index e55fbf80d..5c8b76e43 100644 --- a/app/portainer/views/endpoints/endpointsController.js +++ b/app/portainer/views/endpoints/endpointsController.js @@ -30,18 +30,21 @@ function ($scope, $state, $filter, EndpointService, Notifications, ExtensionMana var TLSCertFile = TLSSkipClientVerify ? null : securityData.TLSCert; var TLSKeyFile = TLSSkipClientVerify ? null : securityData.TLSKey; + var endpointId; $scope.state.actionInProgress = true; EndpointService.createRemoteEndpoint(name, URL, PublicURL, TLS, TLSSkipVerify, TLSSkipClientVerify, TLSCAFile, TLSCertFile, TLSKeyFile) .then(function success(data) { + endpointId = data.Id; var currentEndpointId = EndpointProvider.endpointID(); - EndpointProvider.setEndpointID(data.Id); - ExtensionManager.initEndpointExtensions(data.Id) + EndpointProvider.setEndpointID(endpointId); + ExtensionManager.initEndpointExtensions(endpointId) .then(function success(data) { Notifications.success('Endpoint created', name); $state.reload(); }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to create endpoint'); + EndpointService.deleteEndpoint(endpointId); }) .finally(function final() { $scope.state.actionInProgress = false;