From fe920f3db5102000afe28e6c53041c7ee47d3304 Mon Sep 17 00:00:00 2001 From: Shni Date: Wed, 15 Oct 2025 21:33:53 -0500 Subject: [PATCH] feat(dashboard): agregar manejo de errores y alertas en la carga de items --- .../public/assets/js/dashboard_items.js | 14 ++++++-- .../partials/dashboard/dashboard_items.ejs | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/server/public/assets/js/dashboard_items.js b/src/server/public/assets/js/dashboard_items.js index 095e617..e93a4d4 100644 --- a/src/server/public/assets/js/dashboard_items.js +++ b/src/server/public/assets/js/dashboard_items.js @@ -27,12 +27,20 @@ const list = $('itemsList'); async function fetchItems(){ - if(!guildId) return; + if(!guildId){ showPageAlert('warning','No hay servidor seleccionado. Selecciona un servidor o inicia sesión.'); return; } if(list) list.textContent = 'Cargando items...'; try{ const res = await fetch('/api/dashboard/' + encodeURIComponent(guildId) + '/items', { headers:{ 'Accept':'application/json' } }); - if(!res.ok) throw new Error('fetch-failed'); - const j = await res.json(); if(!j || !j.ok) throw new Error('bad'); + if(!res.ok){ + // Show helpful message depending on status + if(res.status === 401) { showPageAlert('danger','No autenticado. Inicia sesión y vuelve a intentarlo.'); } + else if(res.status === 403) { showPageAlert('danger','No tienes permisos para ver items en este servidor.'); } + else { showPageAlert('danger','Error al cargar items (HTTP ' + res.status + ')'); } + if(list) list.innerHTML = '
Error cargando items: HTTP ' + res.status + '
'; + try{ const errBody = await res.text(); console.debug('items fetch non-ok body:', errBody); }catch(e){} + return; + } + const j = await res.json(); if(!j || !j.ok) { showPageAlert('danger','Respuesta inválida del servidor al listar items'); if(list) list.innerHTML = '
Respuesta inválida del servidor
'; return; } cachedItems = j.items || []; renderList(cachedItems); }catch(err){ if(list) list.innerHTML = '
Error cargando items
'; } diff --git a/src/server/views/partials/dashboard/dashboard_items.ejs b/src/server/views/partials/dashboard/dashboard_items.ejs index 40ce645..a80d723 100644 --- a/src/server/views/partials/dashboard/dashboard_items.ejs +++ b/src/server/views/partials/dashboard/dashboard_items.ejs @@ -7,5 +7,39 @@ +
+ +
+ + <% if (!selectedGuildId) { %> +
Selecciona un servidor en la barra lateral o inicia sesión para administrar items.
+ <% } %> + + + +