handle missing token issues

This commit is contained in:
Sven Czarnian
2022-11-04 15:27:55 +01:00
parent 5bca340bdd
commit ecc01fbb8c

View File

@@ -4,12 +4,16 @@ import { AirportOverview } from '../types';
export class Airport { export class Airport {
static async all(): Promise<AirportOverview[]> { static async all(): Promise<AirportOverview[]> {
const token = sessionStorage.getItem('token');
if (!token) return [];
return axios return axios
.get<AirportOverview[]>(`${Configuration.resourceServer}/airport/all`, { .get<AirportOverview[]>(`${Configuration.resourceServer}/airport/all`, {
headers: { headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`, Authorization: `Bearer ${token}`,
}, },
}) })
.then((response) => response.data); .then((response) => response.data)
.catch(() => []);
} }
} }