Skip to content

Commit

Permalink
Merge pull request #1741 from mozilla/pb/1740-catch-delete-customer-e…
Browse files Browse the repository at this point in the history
…rrors

#1741
r=vbudhram
  • Loading branch information
philbooth committed Jul 11, 2019
2 parents cd6460d + bfede8e commit 94588df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/fxa-auth-server/lib/subhub/client.js
Expand Up @@ -307,12 +307,13 @@ module.exports = function(log, config) {
try {
return await api.deleteCustomer(uid);
} catch (err) {
log.error('subhub.deleteCustomer.failed', { uid, err });

if (err.statusCode === 404) {
throw error.unknownCustomer(uid);
// This method is called optimistically, so swallow `unknownCustomer` errors.
return { message: 'unknown customer' };
}

log.error('subhub.deleteCustomer.failed', { uid, err });

throw err;
}
},
Expand Down
13 changes: 13 additions & 0 deletions packages/fxa-auth-server/test/local/routes/account.js
Expand Up @@ -2780,6 +2780,19 @@ describe('/account/destroy', () => {
});
});

it('should fail if subhub.deleteCustomer fails', async () => {
mockSubhub.deleteCustomer = sinon.spy(async function() {
throw new Error('wibble');
});
let failed = false;
try {
await runTest(buildRoute(), mockRequest);
} catch (err) {
failed = true;
}
assert.isTrue(failed);
});

it('should not attempt to cancel subscriptions with config.subscriptions.enabled = false', async () => {
const route = buildRoute(false);
return runTest(route, mockRequest, () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/fxa-auth-server/test/local/subhub/client.js
Expand Up @@ -567,11 +567,20 @@ describe('subhub client', () => {
assert.deepEqual(response, { message: 'wibble' });
});

it('should throw on unknown user', async () => {
it('should not fail for unknown user', async () => {
mockServer
.delete(`/v1/customer/${UID}`)
.reply(404, { message: 'invalid uid' });
const { subhub } = makeSubject();
const response = await subhub.deleteCustomer(UID);
assert.deepEqual(response, { message: 'unknown customer' });
});

it('should fail for other errors', async () => {
mockServer
.delete(`/v1/customer/${UID}`)
.reply(400, { message: 'wibble' });
const { subhub } = makeSubject();

let failed = false;

Expand All @@ -580,7 +589,7 @@ describe('subhub client', () => {
} catch (err) {
failed = true;

assert.equal(err.errno, error.ERRNO.UNKNOWN_SUBSCRIPTION_CUSTOMER);
assert.equal(err.message, 'wibble');
}

assert.isTrue(failed);
Expand Down

0 comments on commit 94588df

Please sign in to comment.