Skip to content
Permalink
Browse files

fix(api): prevent /account/destroy failing due to subhub errors

  • Loading branch information...
philbooth committed Jul 11, 2019
1 parent cd6460d commit bfede8ef5db95394d1cf9f01a59562d7de97da18
@@ -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;
}
},
@@ -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, () => {
@@ -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;

@@ -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);

0 comments on commit bfede8e

Please sign in to comment.
You can’t perform that action at this time.