From d455ab3fc74ffe287a2fca824209964de0a0c842 Mon Sep 17 00:00:00 2001 From: baron_l Date: Tue, 13 Nov 2018 04:08:12 +0100 Subject: [PATCH] feat(endpoints): enhance offline browsing (#2454) * feat(api): rewrite error response when trying to query a down endpoint * feat(interceptors): adding custom backend return code on offline fastfail --- api/http/handler/endpointproxy/proxy_docker.go | 5 +++++ app/docker/interceptors/containersInterceptor.js | 2 +- app/docker/interceptors/imagesInterceptor.js | 2 +- app/docker/interceptors/infoInterceptor.js | 2 +- app/docker/interceptors/networksInterceptor.js | 2 +- app/docker/interceptors/versionInterceptor.js | 2 +- app/docker/interceptors/volumesInterceptor.js | 2 +- app/portainer/interceptors/endpointStatusInterceptor.js | 2 +- 8 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/http/handler/endpointproxy/proxy_docker.go b/api/http/handler/endpointproxy/proxy_docker.go index f03ca8e67..9ca932a97 100644 --- a/api/http/handler/endpointproxy/proxy_docker.go +++ b/api/http/handler/endpointproxy/proxy_docker.go @@ -1,6 +1,7 @@ package endpointproxy import ( + "errors" "strconv" httperror "github.com/portainer/libhttp/error" @@ -23,6 +24,10 @@ func (handler *Handler) proxyRequestsToDockerAPI(w http.ResponseWriter, r *http. return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint with the specified identifier inside the database", err} } + if endpoint.Status == portainer.EndpointStatusDown { + return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to query endpoint", errors.New("Endpoint is down")} + } + err = handler.requestBouncer.EndpointAccess(r, endpoint) if err != nil { return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", portainer.ErrEndpointAccessDenied} diff --git a/app/docker/interceptors/containersInterceptor.js b/app/docker/interceptors/containersInterceptor.js index f717ea211..066ffe4fe 100644 --- a/app/docker/interceptors/containersInterceptor.js +++ b/app/docker/interceptors/containersInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Containers; diff --git a/app/docker/interceptors/imagesInterceptor.js b/app/docker/interceptors/imagesInterceptor.js index bdfcdd6de..9d79fbc86 100644 --- a/app/docker/interceptors/imagesInterceptor.js +++ b/app/docker/interceptors/imagesInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Images; diff --git a/app/docker/interceptors/infoInterceptor.js b/app/docker/interceptors/infoInterceptor.js index 716d4fbfd..17f310641 100644 --- a/app/docker/interceptors/infoInterceptor.js +++ b/app/docker/interceptors/infoInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Info; diff --git a/app/docker/interceptors/networksInterceptor.js b/app/docker/interceptors/networksInterceptor.js index 85bce4ba2..b5068534c 100644 --- a/app/docker/interceptors/networksInterceptor.js +++ b/app/docker/interceptors/networksInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Networks; diff --git a/app/docker/interceptors/versionInterceptor.js b/app/docker/interceptors/versionInterceptor.js index 4b6ed5776..95a5d56c4 100644 --- a/app/docker/interceptors/versionInterceptor.js +++ b/app/docker/interceptors/versionInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Version; diff --git a/app/docker/interceptors/volumesInterceptor.js b/app/docker/interceptors/volumesInterceptor.js index 268f6a4fd..a42addd2c 100644 --- a/app/docker/interceptors/volumesInterceptor.js +++ b/app/docker/interceptors/volumesInterceptor.js @@ -6,7 +6,7 @@ angular.module('portainer.app') interceptor.responseError = responseErrorInterceptor; function responseErrorInterceptor(rejection) { - if (rejection.status === 502 || rejection.status === -1) { + if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) { var endpoint = EndpointProvider.currentEndpoint(); if (endpoint !== undefined) { var data = endpoint.Snapshots[0].SnapshotRaw.Volumes; diff --git a/app/portainer/interceptors/endpointStatusInterceptor.js b/app/portainer/interceptors/endpointStatusInterceptor.js index 46ca7a42b..9411f8d62 100644 --- a/app/portainer/interceptors/endpointStatusInterceptor.js +++ b/app/portainer/interceptors/endpointStatusInterceptor.js @@ -30,7 +30,7 @@ angular.module('portainer.app') function responseErrorInterceptor(rejection) { var EndpointService = $injector.get('EndpointService'); var url = rejection.config.url; - if ((rejection.status === 502 || rejection.status === -1) && canBeOffline(url) && !EndpointProvider.offlineMode()) { + if ((rejection.status === 502 || rejection.status === 503 || rejection.status === -1) && canBeOffline(url) && !EndpointProvider.offlineMode()) { EndpointProvider.setOfflineMode(true); EndpointService.updateEndpoint(EndpointProvider.endpointID(), {Status: EndpointProvider.endpointStatusFromOfflineMode(true)}); }