Save step errors to editor store
[MAILPOET-4659]
This commit is contained in:
@@ -12,6 +12,7 @@ export type ApiError = {
|
|||||||
status?: number;
|
status?: number;
|
||||||
details?: Error;
|
details?: Error;
|
||||||
params?: Record<string, string>;
|
params?: Record<string, string>;
|
||||||
|
errors?: unknown[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ import apiFetch, { APIFetchOptions } from '@wordpress/api-fetch';
|
|||||||
import { dispatch, StoreDescriptor } from '@wordpress/data';
|
import { dispatch, StoreDescriptor } from '@wordpress/data';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { store as noticesStore } from '@wordpress/notices';
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
|
import { storeName } from './store';
|
||||||
import { ApiError } from '../api';
|
import { ApiError } from '../api';
|
||||||
|
|
||||||
export const registerApiErrorHandler = (): void =>
|
export const registerApiErrorHandler = (): void =>
|
||||||
@@ -16,6 +17,12 @@ export const registerApiErrorHandler = (): void =>
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorObject = error as ApiError;
|
const errorObject = error as ApiError;
|
||||||
const status = errorObject.data?.status;
|
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) {
|
if (status && status >= 400 && status < 500) {
|
||||||
const message = errorObject.message;
|
const message = errorObject.message;
|
||||||
|
Reference in New Issue
Block a user