Skip to content

Commit

Permalink
chore: Capture and process order errors properly in Sentry (#4173)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal authored Mar 3, 2020
1 parent 624d085 commit 471a9ca
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
8 changes: 7 additions & 1 deletion app/controllers/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@ export default Controller.extend({
this.transitionToRoute('orders.new', order.identifier);
})
.catch(async e => {
await Promise.all((attendees ? attendees.toArray() : []).map(attendee => attendee.destroyRecord()));
console.error('Error while saving order', e);
try {
await Promise.allSettled((attendees ? attendees.toArray() : []).map(attendee => attendee.destroyRecord()));
} catch (error) {
console.error('Error while deleting attendees after order failure', error);
}
this.notify.error(this.l10n.t(e.errors[0].detail));
})
.finally(() => {
this.set('isLoading', false);
});
} catch (e) {
console.error('Error while creating order', e);
this.notify.error(this.l10n.t(e));
}
}
Expand Down
43 changes: 36 additions & 7 deletions app/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import * as Sentry from '@sentry/browser';
import { Ember } from '@sentry/integrations';
import { CaptureConsole, Dedupe, Ember } from '@sentry/integrations';
import config from 'open-event-frontend/config/environment';

Sentry.init({
integrations: [new Ember()],
integrations: [
new Ember(),
new Dedupe(),
new CaptureConsole({
levels: ['error']
})
],
beforeSend(event: Sentry.Event) {
const exception = event.exception?.values?.[0];
const errorValue = exception?.value;
if (errorValue?.includes("Ember Data Request") &&
errorValue?.includes("404")) {
// Ignore 404 errors from Ember Data because
// I don't know how to turn them off
return null;
if (errorValue?.includes("Ember Data Request")) {
if (errorValue?.includes("404")) {
// Ignore 404 errors from Ember Data because
// I don't know how to turn them off
return null;
}
}

if (errorValue?.includes("TransitionAborted") &&
Expand All @@ -24,3 +31,25 @@ Sentry.init({
},
...config.sentry
});

Sentry.configureScope(function(scope) {
function addAdapterError(error: any, event: Sentry.Event) {
if (error.isAdapterError) {
event.extra = {
...event.extra,
adapter_errors: error.errors,
adapter_errors_json: JSON.stringify(error.errors)
}
}
}

scope.addEventProcessor(function(event: Sentry.Event, hints: Sentry.EventHint) {
addAdapterError(hints.originalException, event);

const args: any[] = event.extra?.arguments || [];
for (const arg of args) {
addAdapterError(arg, event);
}
return event;
});
});
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(defaults) {
includePolyfill: true
},
storeConfigInMeta : true,
sassOptions : {
sassOptions : {
sourceMapEmbed: true
},
autoprefixer: {
Expand Down

1 comment on commit 471a9ca

@vercel
Copy link

@vercel vercel bot commented on 471a9ca Mar 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.