shell: lib: handle cockpit.user() failures

In our test TestLogin.testFailingWebsocket the dbus calls fail which
fails the promise which was unhandled leading to the tests to fail due
to an unhandled exception.
This commit is contained in:
Jelle van der Waa 2024-03-26 13:59:43 +01:00 committed by Martin Pitt
parent 376bfebb02
commit f2cc9e1a36
3 changed files with 3 additions and 3 deletions

View File

@ -88,7 +88,7 @@ export function usePageLocation() {
const cockpit_user_promise = cockpit.user();
let cockpit_user = null;
cockpit_user_promise.then(user => { cockpit_user = user });
cockpit_user_promise.then(user => { cockpit_user = user }).catch(err => console.log(err));
export function useLoggedInUser() {
const [user, setUser] = useState(cockpit_user);

View File

@ -70,7 +70,7 @@ export class CockpitHosts extends React.Component {
componentDidMount() {
cockpit.user().then(user => {
this.setState({ current_user: user.name || "" });
});
}).catch(exc => console.log(exc));
}
static getDerivedStateFromProps(nextProps, prevState) {

View File

@ -97,7 +97,7 @@ function MachinesIndex(index_options, machines, loader) {
let current_user = "";
cockpit.user().then(user => {
current_user = user.name || "";
});
}).catch(exc => console.log(exc));
/* Navigation */
let ready = false;