Merge pull request #11019 from overleaf/tm-fix-subscription-creation-response-timeout

Fix createSubscription timing out if non-handled error occurs

GitOrigin-RevId: 4f40d7134d81e6c212b045b2b18da36eb0421a43
This commit is contained in:
Thomas 2023-01-17 12:42:23 +01:00 committed by Copybot
parent d01e83b453
commit ae4b4c09b8
2 changed files with 11 additions and 29 deletions

View file

@ -473,6 +473,7 @@ async function createSubscription(req, res) {
{ err, user_id: user._id }, { err, user_id: user._id },
'something went wrong creating subscription' 'something went wrong creating subscription'
) )
throw err
} }
} }
} }

View file

@ -523,8 +523,7 @@ describe('SubscriptionController', function () {
}) })
}) })
it('should handle 3DSecure errors', function (done) { it('should handle 3DSecure errors/recurly transaction errors', function (done) {
this.next = sinon.stub()
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false) this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
this.SubscriptionHandler.promises.createSubscription.rejects( this.SubscriptionHandler.promises.createSubscription.rejects(
new SubscriptionErrors.RecurlyTransactionError({}) new SubscriptionErrors.RecurlyTransactionError({})
@ -541,7 +540,6 @@ describe('SubscriptionController', function () {
}) })
it('should handle validation errors', function (done) { it('should handle validation errors', function (done) {
this.next = sinon.stub()
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false) this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
this.SubscriptionHandler.promises.createSubscription.rejects( this.SubscriptionHandler.promises.createSubscription.rejects(
new Errors.InvalidError('invalid error test') new Errors.InvalidError('invalid error test')
@ -557,37 +555,20 @@ describe('SubscriptionController', function () {
this.SubscriptionController.createSubscription(this.req, this.res) this.SubscriptionController.createSubscription(this.req, this.res)
}) })
it('should handle recurly errors', function (done) { it('should throw errors from createSubscription that are not handled', function (done) {
const genericError = new Error('generic error')
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false) this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
this.SubscriptionHandler.promises.createSubscription.rejects( this.SubscriptionHandler.promises.createSubscription.rejects(genericError)
new SubscriptionErrors.RecurlyTransactionError({})
)
this.HttpErrorHandler.unprocessableEntity = sinon.spy( this.SubscriptionController.createSubscription(
(req, res, info) => { this.req,
expect(req).to.exist this.res,
expect(res).to.exist error => {
expect(info).to.deep.equal('Unknown transaction error') expect(error).to.be.instanceof(Error)
expect(error.message).to.equal(genericError.message)
done() done()
} }
) )
this.SubscriptionController.createSubscription(this.req, this.res)
})
it('should handle invalid error', function (done) {
this.LimitationsManager.promises.userHasV1OrV2Subscription.resolves(false)
this.SubscriptionHandler.promises.createSubscription.rejects(
new Errors.InvalidError({})
)
this.HttpErrorHandler.unprocessableEntity = sinon.spy((req, res) => {
expect(req).to.exist
expect(res).to.exist
done()
})
this.SubscriptionController.createSubscription(this.req, this.res)
}) })
}) })