Commit 1f115a31 authored by Lukas Burgey's avatar Lukas Burgey

Fix error handling on http errors

parent b7fcc664
......@@ -71,7 +71,7 @@ export class UserService {
this.sshKeys$.next(this.sshKeys);
},
this.errorLogger,
this.logErrorAndFetch(),
() => console.log('sar$ is complete'),
);
......@@ -96,7 +96,7 @@ export class UserService {
this.snackBar.open('Logged out');
}
},
this.errorLogger,
this.logErrorAndFetch(),
() => console.log('loggedIn$ completed'),
);
......@@ -150,9 +150,7 @@ export class UserService {
this.userStateUpdate(update.user_state);
}
},
(error: any) => {
console.log(error)
}
this.logErrorAndFetch(),
);
}
......@@ -187,7 +185,7 @@ export class UserService {
if (update) {
// report an occured error
if (update.error) {
this.errorLogger(update.error);
this.logErrorAndFetch(update.error);
}
if (!update.user) {
......@@ -209,7 +207,7 @@ export class UserService {
private fetch(): void {
this.http.get('/backend/api/state').subscribe(
(data: t.StateAPIResult) => this.stateAPIUpdate(data),
(err: any) => this.errorLogger(err, 'receiving data from the server')
this.logErrorAndFetch(),
);
}
......@@ -250,12 +248,19 @@ export class UserService {
return []
}
public errorLogger(error: any, msg?: string): void {
console.log(error);
public logErrorAndFetch(msg?: string): ((any) => void) {
if (msg) {
this.snackBar.open('Error: '+msg);
return (error: any) => {
console.log(error);
this.snackBar.open('Error: '+msg);
this.fetch();
};
} else {
this.snackBar.open('Error');
return (error: any) => {
console.log(error);
this.snackBar.open('Error');
this.fetch();
};
}
}
......@@ -268,12 +273,7 @@ export class UserService {
public logout() {
this.http.post('/backend/auth/v1/logout', {}).subscribe(
(data: t.StateAPIResult) => this.stateAPIUpdate(data),
(err: any) => {
this.errorLogger(err);
// force manual log out
this.loggedIn = false;
this.loggedIn$.next(this.loggedIn);
}
this.logErrorAndFetch(),
);
}
......@@ -283,11 +283,7 @@ export class UserService {
this.snackBar.open('Uploaded questionnaire');
this.userStateUpdate(data);
},
(err) => {
this.snackBar.open('Error uploading questionnaire');
console.log(err);
this.fetch();
}
this.logErrorAndFetch(),
);
}
......@@ -299,11 +295,7 @@ export class UserService {
this.snackBar.open('Deleted user from server');
}
},
(err) => {
this.snackBar.open('Error deleting user from server');
console.log(err);
this.fetch();
}
this.logErrorAndFetch('Error deleting user from server'),
);
}
......@@ -317,7 +309,8 @@ export class UserService {
(newKey: t.SSHKey) => {
this.sshKeys.push(newKey);
this.sshKeys$.next(this.sshKeys);
}
},
this.logErrorAndFetch(),
);
}
......@@ -334,10 +327,12 @@ export class UserService {
);
this.sshKeys$.next(this.sshKeys);
}
}
},
this.logErrorAndFetch(),
);
}
public changeDeployment(action: string, group: t.Group): Observable<t.Deployment> {
const body = {
'type': action,
......@@ -345,6 +340,7 @@ export class UserService {
};
return this.http.post('/backend/api/deployments', body).map(
(newDep: t.Deployment) => newDep,
this.logErrorAndFetch(),
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment