Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): surface save failures in the message template editor (#79457)

posthog[bot]0ce2b71a05b0
diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts
index 46827063b8b9..7f757e953e47 100644
--- a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts
+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts
@@ -96,6 +96,49 @@ describe('messageTemplateLogic', () => {
})
})
+ describe('save failure feedback', () => {
+ beforeEach(() => {
+ jest.clearAllMocks()
+ })
+
+ it.each([
+ {
+ description: '404 tells the user the template is gone from this environment',
+ status: 404,
+ toast: 'This template no longer exists in this environment. It may have been deleted.',
+ withButton: true,
+ },
+ {
+ description: 'other failures fall back to a generic retry message',
+ status: 500,
+ toast: 'Failed to save template. Please try again.',
+ withButton: false,
+ },
+ ])('$description', async ({ status, toast, withButton }) => {
+ useMocks({
+ patch: {
+ '/api/environments/:team_id/messaging_templates/:id/': () => [status, { detail: 'nope' }],
+ },
+ })
+
+ logic = messageTemplateLogic({ id: 'existing-id' })
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ logic.actions.saveTemplate({ id: 'existing-id', name: 'Existing' })
+ }).toDispatchActions(['saveTemplateFailure'])
+
+ if (withButton) {
+ expect(mockToast.error).toHaveBeenCalledWith(
+ toast,
+ expect.objectContaining({ button: expect.anything() })
+ )
+ } else {
+ expect(mockToast.error).toHaveBeenCalledWith(toast)
+ }
+ })
+ })
+
describe('starting-point picker', () => {
it.each([
{
diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts
index a4a741fa7f8a..ed7c86fa1db5 100644
--- a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts
+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts
@@ -372,6 +372,20 @@ export const messageTemplateLogic = kea<messageTemplateLogicType>([
lemonToast.error('Subject is required')
}
},
+ saveTemplateFailure: ({ errorObject }) => {
+ // A 404 means the template no longer resolves for this environment - it was soft-deleted,
+ // or it belongs to a different environment than the one currently selected.
+ if (errorObject?.status === 404) {
+ lemonToast.error('This template no longer exists in this environment. It may have been deleted.', {
+ button: {
+ label: 'Back to library',
+ action: () => router.actions.push(urls.workflows('library')),
+ },
+ })
+ return
+ }
+ lemonToast.error('Failed to save template. Please try again.')
+ },
saveTemplateSuccess: async ({ template }) => {
lemonToast.success('Template saved')
// Clear the unsaved-changes state before navigating so the beforeUnload guard