chat.js 561 B

1234567891011121314151617181920
  1. async function getUserList(q, token) {
  2. if (!token) {
  3. return "not_init";
  4. }
  5. const response = await fetch(`/api/chat/users?q=${encodeURIComponent(q)}`, {
  6. method: "GET",
  7. headers: {
  8. "Authorization": `Bearer ${token}`
  9. }
  10. });
  11. if (!response.ok) {
  12. const errorData = await response.json().catch(() => ({ message: "Respuesta no válida del servidor." }));
  13. throw new Error(errorData.message || `Error del servidor: ${response.status}`);
  14. }
  15. const data = await response.json();
  16. return data.users || [];
  17. }
  18. export { getUserList };