mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-04 23:27:13 +00:00
Merge pull request #1734 from sharelatex/spd-delete-user-crash
Don't fail in refreshFeatures if the v1 user doesn't exist GitOrigin-RevId: 7849f5f942ef39762b40c31a616b51b4b1fe0706
This commit is contained in:
parent
e1ec01eb0f
commit
cc96ecfd74
3 changed files with 21 additions and 3 deletions
|
@ -54,6 +54,7 @@ module.exports = FeaturesUpdater =
|
|||
_getV1Features: (user_id, callback = (error, features = {}) ->) ->
|
||||
V1SubscriptionManager.getPlanCodeFromV1 user_id, (err, planCode, v1Id) ->
|
||||
if err?
|
||||
return callback(null, []) if err?.name == 'NotFoundError'
|
||||
return callback(err)
|
||||
|
||||
callback(err, FeaturesUpdater._mergeFeatures(
|
||||
|
|
|
@ -2,7 +2,7 @@ UserGetter = require "../User/UserGetter"
|
|||
request = require "request"
|
||||
settings = require "settings-sharelatex"
|
||||
logger = require "logger-sharelatex"
|
||||
{ V1ConnectionError } = require "../Errors/Errors"
|
||||
{ V1ConnectionError, NotFoundError } = require "../Errors/Errors"
|
||||
|
||||
module.exports = V1SubscriptionManager =
|
||||
# Returned planCode = 'v1_pro' | 'v1_pro_plus' | 'v1_student' | 'v1_free' | null
|
||||
|
@ -97,4 +97,7 @@ module.exports = V1SubscriptionManager =
|
|||
if 200 <= response.statusCode < 300
|
||||
return callback null, body, v1Id
|
||||
else
|
||||
return callback new Error("non-success code from v1: #{response.statusCode}")
|
||||
if response.statusCode == 404
|
||||
return callback new NotFoundError("v1 user not found: #{userId}")
|
||||
else
|
||||
return callback new Error("non-success code from v1: #{response.statusCode}")
|
||||
|
|
|
@ -179,6 +179,20 @@ describe 'V1SubscriptionManager', ->
|
|||
expect(err).to.exist
|
||||
done()
|
||||
|
||||
describe 'when the call returns an http not-found status code', ->
|
||||
beforeEach ->
|
||||
@V1SubscriptionManager.v1IdForUser = sinon.stub()
|
||||
.yields(null, @v1UserId)
|
||||
@request.yields(null, { statusCode: 404 }, "{}")
|
||||
@call = (cb) =>
|
||||
@V1SubscriptionManager._v1Request @user_id, { url: () -> '/foo' }, cb
|
||||
|
||||
it 'should produce an not-found error', (done) ->
|
||||
@call (err, body, v1Id) =>
|
||||
expect(err).to.exist
|
||||
expect(err.name).to.equal 'NotFoundError'
|
||||
done()
|
||||
|
||||
describe 'v1IdForUser', ->
|
||||
beforeEach ->
|
||||
@UserGetter.getUser = sinon.stub()
|
||||
|
@ -221,4 +235,4 @@ describe 'V1SubscriptionManager', ->
|
|||
it 'should return the v1 user id', (done) ->
|
||||
@call (err, user_id) =>
|
||||
expect(user_id).to.eql 42
|
||||
done()
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue