Skip to content

Commit

Permalink
Add logging of failed validation
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Jul 7, 2022
1 parent 99cb71c commit 8a9895f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/hub/node-tests/routes/profile-purchases-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { registry, setupHub } from '../helpers/server';
import CardSpaceQueries from '../../queries/card-space';
import MerchantInfoQueries from '../../queries/merchant-info';
import shortUUID from 'short-uuid';
import { setupSentry, waitForSentryReport } from '../helpers/sentry';
import { setupStubWorkerClient } from '../helpers/stub-worker-client';
import JobTicketsQueries from '../../queries/job-tickets';

Expand Down Expand Up @@ -30,6 +31,7 @@ class StubInAppPurchases {
}

describe('POST /api/profile-purchases', function () {
setupSentry(this);
let { getJobIdentifiers, getJobPayloads, getJobSpecs } = setupStubWorkerClient(this);

this.beforeEach(function () {
Expand Down Expand Up @@ -352,6 +354,16 @@ describe('POST /api/profile-purchases', function () {
},
],
});

let sentryReport = await waitForSentryReport();

expect(sentryReport.tags).to.deep.equal({
action: 'profile-purchases-route',
});

expect(sentryReport.error?.message).to.equal(
`Unable to validate purchase, response: ${JSON.stringify(purchaseValidationResponse)}`
);
});

it('rejects when the merchant information is incomplete', async function () {
Expand Down
6 changes: 6 additions & 0 deletions packages/hub/routes/profile-purchases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MerchantInfo } from './merchant-infos';
import { validateRequiredFields } from './utils/validation';
import shortUuid from 'short-uuid';
import { JobTicket } from './job-tickets';
import * as Sentry from '@sentry/node';

export default class ProfilePurchasesRoute {
databaseManager = inject('database-manager', { as: 'databaseManager' });
Expand Down Expand Up @@ -174,6 +175,11 @@ export default class ProfilePurchasesRoute {
);

if (!purchaseValidationResult) {
let error = new Error(`Unable to validate purchase, response: ${JSON.stringify(purchaseValidationResponse)}`);
Sentry.captureException(error, {
tags: { action: 'profile-purchases-route' },
});

ctx.status = 422;
ctx.body = {
errors: [
Expand Down

0 comments on commit 8a9895f

Please sign in to comment.