mail page imap connection mime 5 bis rest 3
This commit is contained in:
parent
bdb9e2922b
commit
6e14e85ed1
@ -427,11 +427,27 @@ export default function MailPage() {
|
||||
throw new Error('Failed to fetch emails');
|
||||
}
|
||||
const data = await response.json();
|
||||
// Ensure data is an array
|
||||
setEmails(Array.isArray(data) ? data : []);
|
||||
console.log('API Response:', data); // Debug log
|
||||
// Ensure data is an array and has the expected structure
|
||||
if (Array.isArray(data)) {
|
||||
const validEmails = data.filter(email =>
|
||||
email &&
|
||||
typeof email.id === 'string' &&
|
||||
typeof email.accountId === 'string' &&
|
||||
typeof email.from === 'string' &&
|
||||
typeof email.subject === 'string' &&
|
||||
email.date instanceof Date
|
||||
);
|
||||
console.log('Valid emails:', validEmails); // Debug log
|
||||
setEmails(validEmails);
|
||||
} else {
|
||||
console.warn('API returned non-array data:', data);
|
||||
setEmails([]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching emails:', err);
|
||||
setError(err instanceof Error ? err.message : 'An error occurred');
|
||||
setEmails([]); // Set empty array on error
|
||||
setEmails([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user