Debug: UserProfileView логирует ошибки через /debug/log

This commit is contained in:
root 2026-08-21 12:06:28 +00:00
parent 31a39d7436
commit d5bf42a913

View File

@ -209,6 +209,7 @@ const UserProfileView = {
async render(root, params) {
this.userId = params.userId;
this.userName = params.name || 'Пользователь';
console.log('[UserProfile] render start, userId:', this.userId, 'name:', this.userName, 'params:', JSON.stringify(params));
root.innerHTML = `
<div class="view">
<h1 style="margin:0 0 14px;font-size:22px;">👤 ${escapeHtml(this.userName)}</h1>
@ -220,9 +221,9 @@ const UserProfileView = {
API.UserApi.get(this.userId),
API.ReviewApi.stats(this.userId).catch(() => ({})),
]);
console.log('[UserProfile] loaded:', u && u.id, 'user:', JSON.stringify(user).slice(0,200), 'stats:', JSON.stringify(stats));
this.data = user.user || user;
const u = this.data;
console.log('[UserProfile] loaded:', u && u.id, 'stats:', stats);
const init = ((u.name || u.email || '?')[0] || '?').toUpperCase();
const rating = stats.rating_avg ? Number(stats.rating_avg).toFixed(1) : '—';
const reviewsCount = stats.rating_count || 0;
@ -274,7 +275,11 @@ const UserProfileView = {
const revBtn = document.getElementById('up-reviews');
if (revBtn) revBtn.onclick = () => UserReviewsView.render(root, { userId: this.userId, userName: u.name });
} catch (e) {
console.error('[UserProfile] load failed:', e, 'userId:', this.userId);
console.error('[UserProfile] load failed:', e && e.message, 'userId:', this.userId, 'stack:', e && e.stack);
// ship to backend debug log
try {
fetch('/api/v1/debug/log', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ kind: 'UserProfileError', msg: String(e && e.message), userId: String(this.userId), stack: String(e && e.stack || '').slice(0, 500) }) });
} catch {}
document.getElementById('up-content').innerHTML = `<div class="empty-b">⚠️ Не удалось загрузить</div>`;
App._toast('Ошибка загрузки профиля', 'err');
}