From 65dd14daf304adf012cf1ba220ad0306ec952703 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 14 Feb 2020 14:46:17 +0000 Subject: [PATCH] ui: Gracefully cope with 500 errors from the disco-chain API endpoint (#7291) When connect is disabled the discovery-chain endpoint returns a 500 error status, which we previoulsy did not gracefully cope with. This commit gracefully copes with any errors from the disco-chain endpoint by supressing the error and hiding the Routing tab from the Service detail page. Acceptance test included --- ui-v2/app/routes/dc/services/show.js | 18 +++- .../dc/services/show-routing.feature | 97 ++++++++++++------- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/ui-v2/app/routes/dc/services/show.js b/ui-v2/app/routes/dc/services/show.js index d992a2a223..b604818c76 100644 --- a/ui-v2/app/routes/dc/services/show.js +++ b/ui-v2/app/routes/dc/services/show.js @@ -24,7 +24,23 @@ export default Route.extend({ return hash({ chain: ['connect-proxy', 'mesh-gateway'].includes(get(model, 'item.Service.Kind')) ? null - : this.chainRepo.findBySlug(params.name, dc, nspace), + : this.chainRepo.findBySlug(params.name, dc, nspace).catch(function(e) { + const code = get(e, 'errors.firstObject.status'); + // Currently we are specifically catching a 500, but we return null + // by default, so null for all errors. + // The extra code here is mainly for documentation purposes + // and for if we need to perform different actions based on the error code + // in the future + switch (code) { + case '500': + // connect is likely to be disabled + // we just return a null to hide the tab + // `Connect must be enabled in order to use this endpoint` + return null; + default: + return null; + } + }), ...model, }); }); diff --git a/ui-v2/tests/acceptance/dc/services/show-routing.feature b/ui-v2/tests/acceptance/dc/services/show-routing.feature index fe4ff5b857..ff1b7cdf7e 100644 --- a/ui-v2/tests/acceptance/dc/services/show-routing.feature +++ b/ui-v2/tests/acceptance/dc/services/show-routing.feature @@ -1,37 +1,60 @@ -@setupApplicationTest -Feature: dc / services / Show Routing for Serivce -Scenario: Given a service, the Routing tab should display - Given 1 datacenter model with the value "dc1" - And 1 node models - And 1 service model from yaml - --- - - Service: - Kind: consul - Name: service-0 - ID: service-0-with-id - --- - When I visit the service page for yaml - --- - dc: dc1 - service: service-0 - --- - And the title should be "service-0 - Consul" - And I see routing on the tabs - Scenario: Given a service proxy, the Routing tab should not display - Given 1 datacenter model with the value "dc1" - And 1 node models - And 1 service model from yaml - --- - - Service: - Kind: connect-proxy - Name: service-0-proxy - ID: service-0-proxy-with-id - --- - When I visit the service page for yaml - --- - dc: dc1 - service: service-0-proxy - --- - And the title should be "service-0-proxy - Consul" - And I don't see routing on the tabs - +@setupApplicationTest +Feature: dc / services / Show Routing for Service + Scenario: Given a service, the Routing tab should display + Given 1 datacenter model with the value "dc1" + And 1 node models + And 1 service model from yaml + --- + - Service: + Kind: consul + Name: service-0 + ID: service-0-with-id + --- + When I visit the service page for yaml + --- + dc: dc1 + service: service-0 + --- + And the title should be "service-0 - Consul" + And I see routing on the tabs + Scenario: Given a service proxy, the Routing tab should not display + Given 1 datacenter model with the value "dc1" + And 1 node models + And 1 service model from yaml + --- + - Service: + Kind: connect-proxy + Name: service-0-proxy + ID: service-0-proxy-with-id + --- + When I visit the service page for yaml + --- + dc: dc1 + service: service-0-proxy + --- + And the title should be "service-0-proxy - Consul" + And I don't see routing on the tabs + + Scenario: Given connect is disabled, the Routing tab should not display or error + Given 1 datacenter model with the value "dc1" + And 1 node models + And 1 service model from yaml + --- + - Service: + Kind: consul + Name: service-0 + ID: service-0-with-id + --- + And the url "/v1/discovery-chain/service-0?dc=dc1&ns=@namespace" responds with from yaml + --- + status: 500 + body: "Connect must be enabled in order to use this endpoint" + --- + When I visit the service page for yaml + --- + dc: dc1 + service: service-0 + --- + And I don't see routing on the tabs + And I don't see the "[data-test-error]" element +