fix bugs in the backend classes
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user