mirror of https://github.com/portainer/portainer
				
				
				
			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 fastfailpull/2466/head
							parent
							
								
									0825d05546
								
							
						
					
					
						commit
						d455ab3fc7
					
				| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
package endpointproxy
 | 
					package endpointproxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	httperror "github.com/portainer/libhttp/error"
 | 
						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}
 | 
							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)
 | 
						err = handler.requestBouncer.EndpointAccess(r, endpoint)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", portainer.ErrEndpointAccessDenied}
 | 
							return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", portainer.ErrEndpointAccessDenied}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Containers;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Containers;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Images;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Images;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Info;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Info;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Networks;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Networks;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Version;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Version;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    interceptor.responseError = responseErrorInterceptor;
 | 
					    interceptor.responseError = responseErrorInterceptor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      if (rejection.status === 502 || rejection.status === -1) {
 | 
					      if (rejection.status === 502 || rejection.status === 503 || rejection.status === -1) {
 | 
				
			||||||
        var endpoint = EndpointProvider.currentEndpoint();
 | 
					        var endpoint = EndpointProvider.currentEndpoint();
 | 
				
			||||||
        if (endpoint !== undefined) {
 | 
					        if (endpoint !== undefined) {
 | 
				
			||||||
          var data = endpoint.Snapshots[0].SnapshotRaw.Volumes;
 | 
					          var data = endpoint.Snapshots[0].SnapshotRaw.Volumes;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ angular.module('portainer.app')
 | 
				
			||||||
    function responseErrorInterceptor(rejection) {
 | 
					    function responseErrorInterceptor(rejection) {
 | 
				
			||||||
      var EndpointService = $injector.get('EndpointService');
 | 
					      var EndpointService = $injector.get('EndpointService');
 | 
				
			||||||
      var url = rejection.config.url;
 | 
					      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);
 | 
					        EndpointProvider.setOfflineMode(true);
 | 
				
			||||||
        EndpointService.updateEndpoint(EndpointProvider.endpointID(), {Status: EndpointProvider.endpointStatusFromOfflineMode(true)});
 | 
					        EndpointService.updateEndpoint(EndpointProvider.endpointID(), {Status: EndpointProvider.endpointStatusFromOfflineMode(true)});
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue