Skip to content

Commit

Permalink
chore(dashboard): sentry capture errors on the preview endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
LetItRock committed Dec 2, 2024
1 parent bbb7fec commit f17eec1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import * as Sentry from '@sentry/react';
import { ChannelTypeEnum } from '@novu/shared';

import { usePreviewStep } from '@/hooks';
Expand All @@ -15,7 +16,15 @@ import {
import { useStep } from '@/components/workflow-editor/steps/step-provider';

export function ConfigureInAppStepPreview() {
const { previewStep, data: previewData, isPending: isPreviewPending } = usePreviewStep();
const {
previewStep,
data: previewData,
isPending: isPreviewPending,
} = usePreviewStep({
onError: (error) => {
Sentry.captureException(error);
},
});
const { step, isPending } = useStep();

const { workflowSlug, stepSlug } = useParams<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const InAppEditorPreview = ({ workflow, step, formValues }: InAppEditorPr
const { editorValue, setEditorValue, previewStep, previewData, isPreviewPending } = useEditorPreview({
workflowSlug,
stepSlug,
stepName: step.name,
controlValues: formValues,
});
const [accordionValue, setAccordionValue] = useState<string | undefined>(getInitialAccordionValue(editorValue));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { useCallback, useEffect, useState } from 'react';
import * as Sentry from '@sentry/react';

import { usePreviewStep } from '@/hooks';
import { NovuApiError } from '@/api/api.client';
import { ToastIcon } from '@/components/primitives/sonner';
import { showToast } from '@/components/primitives/sonner-helpers';
import { useDataRef } from '@/hooks/use-data-ref';

export const useEditorPreview = ({
workflowSlug,
stepSlug,
stepName,
controlValues,
}: {
workflowSlug: string;
stepSlug: string;
stepName: string;
controlValues: Record<string, unknown>;
}) => {
const [editorValue, setEditorValue] = useState('{}');
Expand All @@ -27,24 +23,7 @@ export const useEditorPreview = ({
setEditorValue(JSON.stringify(res.previewPayloadExample, null, 2));
},
onError: (error) => {
if (error instanceof NovuApiError) {
showToast({
children: () => (
<>
<ToastIcon variant="error" />
<span className="text-sm">
Failed to preview step <span className="font-bold">{stepName}</span> with error: {error.message}
</span>
</>
),
options: {
position: 'bottom-right',
classNames: {
toast: 'ml-10 mb-4',
},
},
});
}
Sentry.captureException(error);
},
});
const dataRef = useDataRef({
Expand Down

0 comments on commit f17eec1

Please sign in to comment.