Skip to content

Commit

Permalink
fix: Log unhandled errors during license activation (no-changelog) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
csuermann authored May 3, 2023
1 parent e88232e commit 97578c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions packages/cli/src/license/license.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,29 @@ licenseController.post(
} catch (e) {
const error = e as Error & { errorId?: string };

let message = 'Failed to activate license';

//override specific error messages (to map License Server vocabulary to n8n terms)
switch (error.errorId ?? 'UNSPECIFIED') {
case 'SCHEMA_VALIDATION':
error.message = 'Activation key is in the wrong format';
message = 'Activation key is in the wrong format';
break;
case 'RESERVATION_EXHAUSTED':
error.message =
message =
'Activation key has been used too many times. Please contact [email protected] if you would like to extend it';
break;
case 'RESERVATION_EXPIRED':
error.message = 'Activation key has expired';
message = 'Activation key has expired';
break;
case 'NOT_FOUND':
case 'RESERVATION_CONFLICT':
error.message = 'Activation key not found';
message = 'Activation key not found';
break;
default:
getLogger().error(message, { stack: error.stack ?? 'n/a' });
}

throw new ResponseHelper.BadRequestError(error.message);
throw new ResponseHelper.BadRequestError(message);
}

// Return the read data, plus the management JWT
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/integration/license.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ describe('POST /license/activate', () => {

test('errors out properly', async () => {
License.prototype.activate = jest.fn().mockImplementation(() => {
throw new Error(INVALID_ACIVATION_KEY_MESSAGE);
throw new Error(ACTIVATION_FAILED_MESSAGE);
});

await authOwnerAgent
.post('/license/activate')
.send({ activationKey: 'abcde' })
.expect(400, { code: 400, message: INVALID_ACIVATION_KEY_MESSAGE });
.expect(400, { code: 400, message: ACTIVATION_FAILED_MESSAGE });
});
});

Expand Down Expand Up @@ -135,5 +135,5 @@ const DEFAULT_POST_RESPONSE: { data: ILicensePostResponse } = {
};

const NON_OWNER_ACTIVATE_RENEW_MESSAGE = 'Only an instance owner may activate or renew a license';
const INVALID_ACIVATION_KEY_MESSAGE = 'Invalid activation key';
const ACTIVATION_FAILED_MESSAGE = 'Failed to activate license';
const RENEW_ERROR_MESSAGE = 'Something went wrong when trying to renew license';

0 comments on commit 97578c7

Please sign in to comment.