fix bugs in the backend classes

This commit is contained in:
Sven Czarnian
2022-11-05 00:30:48 +01:00
orang tua df0a6ade57
melakukan e1ced4e9f8
4 mengubah file dengan 35 tambahan dan 12 penghapusan

Melihat File

@@ -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,
};
});
}
}