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
pull/2466/head
baron_l 2018-11-13 04:08:12 +01:00 committed by Anthony Lapenna
parent 0825d05546
commit d455ab3fc7
8 changed files with 12 additions and 7 deletions

View File

@ -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}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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)});
}