use some status information to handle errors better
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
import axios from 'axios';
|
||||
import { Configuration } from './configuration';
|
||||
import { Session } from './session';
|
||||
import { AirportOverview } from '../types';
|
||||
import {
|
||||
AirportOverviewBackend,
|
||||
AirportOverview,
|
||||
BackendReturnStatus,
|
||||
} from '../types';
|
||||
|
||||
export class Airport {
|
||||
static async all(): Promise<AirportOverview[]> {
|
||||
static async all(): Promise<AirportOverviewBackend> {
|
||||
const token = Session.bearerToken();
|
||||
if (!token) return [];
|
||||
if (!token) {
|
||||
return {
|
||||
status: BackendReturnStatus.Unauthorized,
|
||||
airports: [],
|
||||
};
|
||||
}
|
||||
|
||||
return axios
|
||||
.get<AirportOverview[]>(`${Configuration.resourceServer}/airport/all`, {
|
||||
@@ -14,7 +23,17 @@ export class Airport {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((response) => response.data)
|
||||
.catch(() => []);
|
||||
.then((response) => {
|
||||
return {
|
||||
status: BackendReturnStatus.Ok,
|
||||
airports: response.data,
|
||||
};
|
||||
})
|
||||
.catch((err) => {
|
||||
return {
|
||||
status: err.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
airports: [],
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user