Originally created utils file for signup with the following functions:

src/components/site/signup/utils.ts
- setYupErrors()
- handleApiResponse()
- handleValidationError()
- handleApiResponseWithState()

then decided they could be useful throughout the app, broke up the following functions into the following files/folders:

src/utils/apiValidationHandlerUtils.ts
- setYupErrors()
- normalizeApiErrors()
- handleValidationError()

src/utils/apiResponseHandlerUtils.ts
- apiResponseHandlerUtils.ts

src/components/site/signup/utils.ts
- handleApiResponseWithState()

With assistance from you before, we changed setYupErrors() and handleValidationError from:

export function setYupErrors(validationError: any, setFormValidationErrors: Dispatch<any>)
{
	if (validationError.inner)
	{
		const yupErrors: Record<string, string[]> = {};
		
		validationError.inner.forEach((error: any) =>
		{
			if (!yupErrors[error.path])
			{
				yupErrors[error.path] = [];
			}
			
			yupErrors[error.path].push(error.message);
		});
		
		console.log('Yup Errors:', yupErrors);// TODO <-- CHANGE DEBUG CONSOLE TO LOGGER
		
		setFormValidationErrors(yupErrors);
	}
	else
	{
		console.warn('ValidationError has no inner array:', validationError);// TODO <-- CHANGE DEBUG CONSOLE TO LOGGER
		
		setFormValidationErrors({});
	}
}

export function handleValidationError(
	error: any,
	setErrorMessage: Dispatch<SetStateAction<string | null>>,
	setFormValidationErrors: Dispatch<SetStateAction<Record<string, any>>>
): void
{
	console.log('handleValidationError called with:', error);// TODO <-- CHANGE DEBUG CONSOLE TO LOGGER

	if (error.name === 'ValidationError')
	{
		console.log('Detected Yup ValidationError', error.inner);// TODO <-- CHANGE DEBUG CONSOLE TO LOGGER
	
		if (error.inner && error.inner.length > 0)
		{
			setYupErrors(error, setFormErrors);
			setError(error.inner[0].message);// set first validation error as general error message
		}
		else
		{
			setErrorMessage(error.message);
			setFormValidationErrors({});
		}
	}
	else
	{
		// Fallback: set error message from API or unknown error
		setErrorMessage(error.message || 'Unknown error occurred');
	}
}


To:

export function setYupErrors(
	validationError: yup.ValidationError,
	setFormValidationErrors: Dispatch<SetStateAction<ApiErrorDetail>>
): void
{
	if (validationError?.inner && Array.isArray(validationError.inner))
	{
		const yupErrors: ApiErrorDetail = {};
		
		validationError.inner.forEach((errorItem) =>
		{
			if (errorItem.path)
			{
				const existing = yupErrors[errorItem.path];
				
				if (existing === undefined)
				{
					yupErrors[errorItem.path] = errorItem.message;
				}
				else if (Array.isArray(existing))
				{
					existing.push(errorItem.message);
				}
				else
				{
					yupErrors[errorItem.path] = [existing, errorItem.message];
				}
			}
		});
		
		console.log('Yup validation errors:', yupErrors);//<!-- TODO Console/Logger Debug
		//logger.log('Yup validation errors:', yupErrors);
		
		setFormValidationErrors(yupErrors);
	}
	else
	{
		console.warn('Yup ValidationError missing inner array or invalid format:', validationError);//<!-- TODO Console/Logger Debug
		//logger.warn('Yup ValidationError missing inner array or invalid format:', validationError);
		
		setFormValidationErrors({});
	}
}

export function normalizeApiErrors(errors: any): ApiErrorDetail
{
	if (!errors || typeof errors !== 'object')
	{
		return {};
	}
	
	const normalized: ApiErrorDetail = {};
	
	Object.entries(errors).forEach(([field, value]) =>
	{
		if (Array.isArray(value))
		{
			const filtered = value.filter((msg) => typeof msg === 'string' && msg.trim() !== '');
			
			normalized[field] = filtered.length === 1 ? filtered[0] : filtered;
		}
		else if (typeof value === 'string' && value.trim() !== '')
		{
			normalized[field] = value;
		}
		
		else 
		{
			/**
			* If value is something else (object etc.), ignore or transform as needed
			* For now, ignore silently
			*/
			console.log('Normalize Api Error - Unexpected value:', value);//<!-- TODO Console/Logger Debug
			//logger.log('Normalize Api Error - Unexpected value:', value);
		}
	});
	
	return normalized;
}

export function handleValidationError
(
	error: any,
	setErrorMessage: Dispatch<SetStateAction<string | null>>,
	setFormValidationErrors: Dispatch<SetStateAction<ApiErrorDetail>>,
	emitGlobalAlert: boolean = true// default param to allow skipping alert if needed
): void
{
	// Yup validation error path
	if (error?.name === 'ValidationError' && Array.isArray(error.inner))
	{
		
		const validationErrors: ApiErrorDetail = {};
		
		error.inner.forEach((errorItem: any) =>
		{
			if (errorItem.path && !(errorItem.path in validationErrors))
			{
				validationErrors[errorItem.path] = errorItem.message;
			}
		});
		
		setFormValidationErrors(validationErrors);
		
		const firstErrorMessage = error.inner.length > 0 ? error.inner[0].message : error.message;
		
		setErrorMessage(firstErrorMessage);
		
		if (emitGlobalAlert)
		{
			emitEvent('alert', { type: 'danger', message: firstErrorMessage });
		}
		
		console.warn('Yup validation error:', error);//<!-- TODO Console/Logger Debug
		//logger.warn('Yup validation error:', error);
		
	}
	
	// API validation error response path
	else if (error?.errors && typeof error.errors === 'object')
	{
		// Backend or API validation errors (expected to be ApiErrorDetail shape or close)
		const normalizedErrors = normalizeApiErrors(error.errors);
		
		setFormValidationErrors(normalizedErrors);
		
		// Derive general message from API response message or first field error
		const generalErrorMessage = typeof error.message === 'string' && error.message.trim() !== '' 
			? error.message : Object.values(normalizedErrors)[0] ?? 'Validation failed';
			
		setErrorMessage(generalErrorMessage);
		
		if (emitGlobalAlert)
		{
			emitEvent('alert', { type: 'danger', message: generalErrorMessage });
		}
		
		console.warn('API validation error:', error);//<!-- TODO Console/Logger Debug
		//logger.warn('API validation error:', error);
	}
	
	// Unknown/error fallback
	else
	{
		// Other kinds of errors (network, unknown, etc.)
		const fallbackErrorMessage = error?.message || 'An unknown error occurred.';
		
		setErrorMessage(fallbackErrorMessage);
		setFormValidationErrors({});
		
		if (emitGlobalAlert)
		{
			emitEvent('alert', { type: 'danger', message: fallbackErrorMessage });
		}
		
		console.error('Unhandled error:', error);//<!-- TODO Console/Logger Debug
		//logger.error('Unhandled error:', error);
	}
}


Im thinking setYupErrors should not be exported, it should only be handled by handleValidationError as it is orignally. What do you think?