Commit 8f07efc4 authored by Lukas Burgey's avatar Lukas Burgey

Make http error handling consistent

Closes #5
parent a1a5727d
...@@ -218,13 +218,7 @@ export class UserService { ...@@ -218,13 +218,7 @@ export class UserService {
if (fetch) { if (fetch) {
this.fetch(); this.fetch();
} }
} return EMPTY
}
private catchError(fetch: boolean, msg?: string) {
return (error: any) => {
this.handleError(fetch, msg)(error);
return EMPTY;
} }
} }
...@@ -258,14 +252,18 @@ export class UserService { ...@@ -258,14 +252,18 @@ export class UserService {
} }
public sentQuestionnaire(stateItemID: number, answers: Object) { public sentQuestionnaire(stateItemID: number, answers: Object) {
return this.http.post<Deployment>('/backend/api/questionnaire?id='+String(stateItemID), answers).subscribe( return this.http.post<Deployment>('/backend/api/questionnaire?id='+String(stateItemID), answers).pipe(
catchError(this.handleError(true, "Error submitting questionnaire")),
).subscribe(
(dep: Deployment) => this.updateDeployment(dep), (dep: Deployment) => this.updateDeployment(dep),
this.logErrorAndFetch, this.logErrorAndFetch,
); );
} }
public deleteUser() { public deleteUser() {
return this.http.delete('/backend/api/delete_user').subscribe( return this.http.delete('/backend/api/delete_user').pipe(
catchError(this.handleError(true, "Error deleting user")),
).subscribe(
(data: {deleted: boolean}) => { (data: {deleted: boolean}) => {
if (data && data.deleted) { if (data && data.deleted) {
this.user$.next(undefined); this.user$.next(undefined);
...@@ -277,7 +275,9 @@ export class UserService { ...@@ -277,7 +275,9 @@ export class UserService {
} }
public uploadSshKey(formData: FormData): void { public uploadSshKey(formData: FormData): void {
this.http.post<SSHKey>('/backend/api/sshkey', formData).subscribe( this.http.post<SSHKey>('/backend/api/sshkey', formData).pipe(
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(newKey: SSHKey) => { (newKey: SSHKey) => {
this.sshKeys.push(newKey); this.sshKeys.push(newKey);
this.sshKeys$.next(this.sshKeys); this.sshKeys$.next(this.sshKeys);
...@@ -291,7 +291,9 @@ export class UserService { ...@@ -291,7 +291,9 @@ export class UserService {
return this.http.post('/backend/api/sshkey', { return this.http.post('/backend/api/sshkey', {
'type': 'remove', 'type': 'remove',
'id': key.id, 'id': key.id,
}).subscribe( }).pipe(
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(data: {deleted: boolean}) => { (data: {deleted: boolean}) => {
if (data && data.deleted) { if (data && data.deleted) {
this.sshKeys = this.sshKeys.filter( this.sshKeys = this.sshKeys.filter(
...@@ -310,7 +312,7 @@ export class UserService { ...@@ -310,7 +312,7 @@ export class UserService {
'vo': vo.id, 'vo': vo.id,
}; };
this.http.post<Deployment>('/backend/api/deployments', body).pipe( this.http.post<Deployment>('/backend/api/deployments', body).pipe(
catchError(this.catchError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(dep: Deployment) => this.updateDeployment(dep), (dep: Deployment) => this.updateDeployment(dep),
); );
...@@ -322,7 +324,7 @@ export class UserService { ...@@ -322,7 +324,7 @@ export class UserService {
'service': service.id, 'service': service.id,
}; };
this.http.post<Deployment>('/backend/api/deployments', body).pipe( this.http.post<Deployment>('/backend/api/deployments', body).pipe(
catchError(this.catchError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(dep: Deployment) => this.updateDeployment(dep), (dep: Deployment) => this.updateDeployment(dep),
); );
......
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