Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more error handeling #609

Merged
merged 6 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions website/src/components/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ import { autorefresh } from '../Util';
import { DeviceListItem } from './DeviceListItem';
import { AddDevice } from './AddDevice';
import { Loading } from './Loading';
import { AppState } from '../AppState';
import { Error } from './Error';
import { Card, CardContent, CardHeader, Skeleton } from '@mui/material';
import { DeviceListItemSkeleton } from './DeviceListItemSkeleton';
import { AddDeviceSkeleton } from './AddDeviceSkeleton';

export const Devices = observer(
class Devices extends React.Component {
devices = autorefresh(30, async () => {
return (await grpc.devices.listDevices({})).items;
try{
const res = await grpc.devices.listDevices({});
return res.items
} catch (error: any){
console.log('An error occurred:', error)
AppState.loadingError = error.message
return null
}
});

constructor(props: {}) {
Expand All @@ -30,6 +39,9 @@ export const Devices = observer(
}

render() {
if(AppState.loadingError){
return <Error message={AppState.loadingError} />
}
if (!this.devices.current) {
return (
<Grid container spacing={3} justifyContent="center">
Expand All @@ -48,7 +60,6 @@ export const Devices = observer(
</Grid>
);
}

return (
<Grid container spacing={3} justifyContent="center">
<Grid item xs={12}>
Expand Down
31 changes: 23 additions & 8 deletions website/src/pages/admin/AllDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,31 @@ import { User } from '../../sdk/users_pb';
import { lastSeen, lazy } from '../../Util';
import numeral from "numeral";
import { Loading } from '../../components/Loading';
import { Error } from '../../components/Error';

export const AllDevices = observer(class AllDevices extends React.Component {
users = lazy(async () => {
const res = await grpc.users.listUsers({});
return res.items;
try {
const result = await grpc.users.listUsers({});
return result.items;
} catch (error: any) {
console.error('An error occurred:', error);
AppState.loadingError = error.message;
return null;
}
});

devices = lazy(async () => {
const res = await grpc.devices.listAllDevices({});
let deviceList = res.items;
deviceList.sort((d1, d2) => (d2.lastHandshakeTime ? d2.lastHandshakeTime.seconds : 0) - (d1.lastHandshakeTime ? d1.lastHandshakeTime.seconds : 0));
return deviceList;
try {
const res = await grpc.devices.listAllDevices({});
let deviceList = res.items;
deviceList.sort((d1, d2) => (d2.lastHandshakeTime ? d2.lastHandshakeTime.seconds : 0) - (d1.lastHandshakeTime ? d1.lastHandshakeTime.seconds : 0));
return deviceList;
}catch (error: any) {
console.error('An error occurred:', error);
AppState.loadingError = error.message
return null
}
});

deleteUser = async (user: User.AsObject) => {
Expand All @@ -55,9 +68,11 @@ export const AllDevices = observer(class AllDevices extends React.Component {

render() {
if (!this.devices.current || !this.users.current) {
return <Loading />;
return <Loading />;
}
if(AppState.loadingError){
return <Error message={AppState.loadingError} />
}

const users = this.users.current;
const devices = this.devices.current;

Expand Down