Save step errors to editor store

[MAILPOET-4659]
This commit is contained in:
Jan Jakes
2022-10-05 12:55:08 +02:00
committed by Jan Jakeš
parent 4bb2fa7599
commit 64acd597ca
2 changed files with 8 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import apiFetch, { APIFetchOptions } from '@wordpress/api-fetch';
import { dispatch, StoreDescriptor } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { storeName } from './store';
import { ApiError } from '../api';
export const registerApiErrorHandler = (): void =>
@@ -16,6 +17,12 @@ export const registerApiErrorHandler = (): void =>
} catch (error) {
const errorObject = error as ApiError;
const status = errorObject.data?.status;
const code = errorObject.code;
if (code === 'mailpoet_automation_workflow_not_valid') {
dispatch(storeName).setErrors({ steps: errorObject.data.errors });
return undefined;
}
if (status && status >= 400 && status < 500) {
const message = errorObject.message;