Private
Public Access
añadida redireccion si falla al obtener grupos
This commit is contained in:
1 parent
5fa3fd7cc5
commit
f3edc5ceb2
1 file changed
+7
-1
@@ -1,10 +1,16 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import type { Usuario, GruposYPermisosResponse } from '../../types';
|
||||
import { API_URL } from '../env';
|
||||
import { getToken } from './token';
|
||||
import { getToken, removeToken, removeAuthTokens } from './token';
|
||||
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
|
||||
if (error.error) {
|
||||
removeToken();
|
||||
removeAuthTokens();
|
||||
goto('/');
|
||||
}
|
||||
throw new Error(error.message || error.error || 'Error en la petición');
|
||||
}
|
||||
return response.json();
|
||||
|
||||
Reference in new issue
Block a user