From 82a8e370710724b5239af4dc62b4ee513d7cd917 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 19 Jun 2018 16:25:31 +0100 Subject: [PATCH] Handle V1 connection refused when getting v1 subscription --- .../app/coffee/Features/Project/ProjectController.coffee | 6 +++++- .../Features/Subscription/V1SubscriptionManager.coffee | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 8ea2dc3189..05ebb9f108 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -27,6 +27,7 @@ CollaboratorsHandler = require '../Collaborators/CollaboratorsHandler' Modules = require '../../infrastructure/Modules' ProjectEntityHandler = require './ProjectEntityHandler' crypto = require 'crypto' +{ V1ConnectionError } = require '../Errors/Errors' module.exports = ProjectController = @@ -183,7 +184,10 @@ module.exports = ProjectController = return cb(null, projects: [], tags: [], noConnection: true) return cb(error, projects[0]) # hooks.fire returns an array of results, only need first hasSubscription: (cb)-> - LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, cb + LimitationsManager.userHasSubscriptionOrIsGroupMember currentUser, (error, hasSub) -> + if error? and error instanceof V1ConnectionError + return cb(null, true) + return cb(error, hasSub) user: (cb) -> User.findById user_id, "featureSwitches overleaf awareOfV2 features", cb }, (err, results)-> diff --git a/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee b/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee index dcf23a3453..857881df4d 100644 --- a/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee +++ b/services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee @@ -2,6 +2,7 @@ UserGetter = require "../User/UserGetter" request = require "request" settings = require "settings-sharelatex" logger = require "logger-sharelatex" +{ V1ConnectionError } = require "../Errors/Errors" module.exports = V1SubscriptionManager = # Returned planCode = 'v1_pro' | 'v1_pro_plus' | 'v1_student' | 'v1_free' | null @@ -58,7 +59,10 @@ module.exports = V1SubscriptionManager = json: true, timeout: 5 * 1000 }, (error, response, body) -> - return callback(error) if error? + if error? + # Specially handle no connection err, so warning can be shown + error = new V1ConnectionError('No V1 connection') if error.code == 'ECONNREFUSED' + return callback(error) if 200 <= response.statusCode < 300 return callback null, body else