fix bugs in the backend classes
This commit is contained in:
@@ -31,7 +31,7 @@ export class Airport {
|
||||
})
|
||||
.catch((err) => {
|
||||
return {
|
||||
status: err.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
status: err.response.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
airports: [],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ export class Auth {
|
||||
})
|
||||
.then(() => BackendReturnStatus.Ok)
|
||||
.catch((err) => {
|
||||
if (err.status === 401) return BackendReturnStatus.Unauthorized;
|
||||
if (err.response.status === 401) return BackendReturnStatus.Unauthorized;
|
||||
return BackendReturnStatus.Failure;
|
||||
});
|
||||
}
|
||||
@@ -49,23 +49,25 @@ export class Auth {
|
||||
})
|
||||
.catch((err) => {
|
||||
return {
|
||||
status: err.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
status: err.response.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
user: DefaultUser,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
static async refreshRadarScopeKey(): Promise<boolean> {
|
||||
static async refreshRadarScopeKey(): Promise<BackendReturnStatus> {
|
||||
const token = Session.bearerToken();
|
||||
if (!token) return false;
|
||||
if (!token) return BackendReturnStatus.Unauthorized;
|
||||
|
||||
return axios
|
||||
.get<void>(`${Configuration.resourceServer}/auth/refreshRadarScopeKey`, {
|
||||
.patch<void>(`${Configuration.resourceServer}/auth/refreshRadarScopeKey`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
.then(() => BackendReturnStatus.Ok)
|
||||
.catch((err) => {
|
||||
return err.response.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import axios from 'axios';
|
||||
import { Configuration } from './configuration';
|
||||
import { Session } from './session';
|
||||
import { BackendReturnStatus, TimestampBackend } from '../types';
|
||||
|
||||
export class System {
|
||||
static async timestamp(): Promise<number> {
|
||||
static async timestamp(): Promise<TimestampBackend> {
|
||||
const token = Session.bearerToken();
|
||||
if (!token) return 0;
|
||||
if (!token) {
|
||||
return {
|
||||
status: BackendReturnStatus.Unauthorized,
|
||||
timestamp: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return axios
|
||||
.get<number>(`${Configuration.resourceServer}/system/timestamp`, {
|
||||
@@ -13,7 +19,17 @@ export class System {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((response) => response.data)
|
||||
.catch(() => 0);
|
||||
.then((response) => {
|
||||
return {
|
||||
status: BackendReturnStatus.Ok,
|
||||
timestamp: response.data,
|
||||
};
|
||||
})
|
||||
.catch((err) => {
|
||||
return {
|
||||
status: err.response.status === 401 ? BackendReturnStatus.Unauthorized : BackendReturnStatus.Failure,
|
||||
timestamp: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,3 +40,8 @@ export interface IAuthState {
|
||||
valid: boolean,
|
||||
user: User,
|
||||
};
|
||||
|
||||
export interface TimestampBackend {
|
||||
status: BackendReturnStatus;
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user