Merge pull request #58 from WIT-LAB-LLC/develop

Develop
This commit is contained in:
pennyteenycat 2025-12-07 04:16:55 +03:00 committed by GitHub
commit 8ad5067f79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -132,8 +132,20 @@ export const useAuth = ({ funnelId, googleAnalyticsId, registrationData }: IUseA
} catch (err) { } catch (err) {
// Extract error message and suggestion from API error // Extract error message and suggestion from API error
if (err instanceof ApiError && err.data) { if (err instanceof ApiError && err.data) {
const errorData = err.data as { errors?: Array<{ msg: string; path: string }> }; const errorData = err.data as {
const emailError = errorData.errors?.find(e => e.path === 'email'); errors?: Array<{ msg: string; path: string }>;
status?: string;
message?: string;
};
// Handle service error format: { status: "error", message: "..." }
if (errorData.status === 'error' && errorData.message) {
setError(errorData.message);
setSuggestedEmail(null);
}
// Handle express-validator format: { errors: [{ msg, path }] }
else if (errorData.errors) {
const emailError = errorData.errors.find(e => e.path === 'email');
if (emailError) { if (emailError) {
setError(emailError.msg); setError(emailError.msg);
@ -145,6 +157,10 @@ export const useAuth = ({ funnelId, googleAnalyticsId, registrationData }: IUseA
} else { } else {
setSuggestedEmail(null); setSuggestedEmail(null);
} }
} else {
setError(errorData.errors[0]?.msg || 'Email validation failed');
setSuggestedEmail(null);
}
} else { } else {
setError('Email validation failed'); setError('Email validation failed');
setSuggestedEmail(null); setSuggestedEmail(null);