From 8492373a14d8a1aa015989697bf4e9df03cb9c94 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 19 Jun 2018 16:24:27 +0100 Subject: [PATCH 1/4] Add V1ConnectionError --- services/web/app/coffee/Features/Errors/Errors.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/web/app/coffee/Features/Errors/Errors.coffee b/services/web/app/coffee/Features/Errors/Errors.coffee index af1e437d4b..25b3f3e06d 100644 --- a/services/web/app/coffee/Features/Errors/Errors.coffee +++ b/services/web/app/coffee/Features/Errors/Errors.coffee @@ -61,6 +61,13 @@ ProjectHistoryDisabledError = (message) -> return error ProjectHistoryDisabledError.prototype.__proto___ = Error.prototype +V1ConnectionError = (message) -> + error = new Error(message) + error.name = "V1ConnectionError" + error.__proto__ = V1ConnectionError.prototype + return error +V1ConnectionError.prototype.__proto___ = Error.prototype + module.exports = Errors = NotFoundError: NotFoundError ServiceNotConfiguredError: ServiceNotConfiguredError @@ -71,3 +78,4 @@ module.exports = Errors = UnsupportedExportRecordsError: UnsupportedExportRecordsError V1HistoryNotSyncedError: V1HistoryNotSyncedError ProjectHistoryDisabledError: ProjectHistoryDisabledError + V1ConnectionError: V1ConnectionError From 82a8e370710724b5239af4dc62b4ee513d7cd917 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 19 Jun 2018 16:25:31 +0100 Subject: [PATCH 2/4] 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 From 8de9e9fae43f234d45e51e9f2720e835de028630 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 19 Jun 2018 16:25:56 +0100 Subject: [PATCH 3/4] Use error type instead of error message to check v1 connection error --- .../web/app/coffee/Features/Project/ProjectController.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 05ebb9f108..1b7051e39a 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -180,7 +180,7 @@ module.exports = ProjectController = ProjectGetter.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref tokens', cb v1Projects: (cb) -> Modules.hooks.fire "findAllV1Projects", user_id, (error, projects = []) -> - if error? and error.message == 'No V1 connection' + if error? and error instanceof V1ConnectionError return cb(null, projects: [], tags: [], noConnection: true) return cb(error, projects[0]) # hooks.fire returns an array of results, only need first hasSubscription: (cb)-> From 6c1994e25b815a1970e6c64d292eb8289703d14d Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Wed, 20 Jun 2018 11:19:23 +0100 Subject: [PATCH 4/4] Stub errors in tests to cache --- .../web/test/unit/coffee/Project/ProjectControllerTests.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee index 1b66ba9bf9..8de7c6aed1 100644 --- a/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectControllerTests.coffee @@ -5,6 +5,7 @@ path = require('path') sinon = require('sinon') modulePath = path.join __dirname, "../../../../app/js/Features/Project/ProjectController" expect = require("chai").expect +Errors = require "../../../../app/js/Features/Errors/Errors" describe "ProjectController", -> @@ -100,6 +101,7 @@ describe "ProjectController", -> "../Collaborators/CollaboratorsHandler": @CollaboratorsHandler "../../infrastructure/Modules": @Modules "./ProjectEntityHandler": @ProjectEntityHandler + "../Errors/Errors": Errors @projectName = "£12321jkj9ujkljds" @req =