export const logActionErrorMiddleware = (logger) => () => (next) => (action) => {
    const unknownAction = action;
    if (!unknownAction.error) {
        return next(action);
    }
    const error = unknownAction.error;
    const errorPayloadMessage = [
        unknownAction.payload?.errorCode,
        unknownAction.payload?.message,
    ]
        .filter(Boolean)
        .join(' - ');
    if (!unknownAction.payload?.ignored) {
        logger.error(errorPayloadMessage ||
            error.stack ||
            error.message ||
            error.name ||
            'Error', `Action dispatch error ${unknownAction.type}`, action);
    }
    // Validation errors should prevent further dispatching
    if (unknownAction.error.name === 'SchemaValidationError') {
        return;
    }
    return next(action);
};
export const logActionMiddleware = (logger) => (api) => (next) => (action) => {
    logger.debug({
        action,
        nextState: api.getState(),
    }, `Action dispatched: ${action.type}`);
    return next(action);
};
