generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from amosproj/258-display-more-precise-error-…
…messages-eg-when-trying-to-log-in-with-not-existing-mail-adress Improve error messages, add new error message service
- Loading branch information
Showing
9 changed files
with
122 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...talIdentity-frontend/src/app/services/error-message-service/error-message.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { ErrorMessageService } from './error-message.service'; | ||
|
||
describe('ErrorMessageService', () => { | ||
let service: ErrorMessageService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ErrorMessageService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
src/digitalIdentity-frontend/src/app/services/error-message-service/error-message.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { MatDialog } from '@angular/material/dialog'; | ||
import { InformationPopUpComponent } from 'src/app/shared/pop-up/information-pop-up/information-pop-up.component'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ErrorMessageService { | ||
private dialogOpen = false; | ||
|
||
constructor(private matDialog: MatDialog) {} | ||
|
||
openHttpErrorDialog(error: HttpErrorResponse) { | ||
let data = { | ||
header: 'Process failed!', | ||
text: 'Error ' + error.status + ' \n' + error.error, | ||
}; | ||
|
||
if (error.status == 401) { | ||
data = { | ||
header: 'Login session expired (401)', | ||
text: 'Please log in to your account', | ||
}; | ||
} | ||
|
||
if (error.status >= 500) { | ||
data = { | ||
header: 'Internal Error (' + error.status + ')', | ||
text: | ||
"The server isn't configured correctly, is unavailable at the moment or a connected service doesn't work properly. This error message could help:\n\n\n" + | ||
error.message + | ||
'\n\n' + | ||
error.error, | ||
}; | ||
if (typeof error.error === 'string' || error.error instanceof String) { | ||
if (error.error.length < 55) { | ||
data.header = String(error.error); | ||
data.text = ''; | ||
} | ||
} | ||
|
||
if (data.text.includes('Error occurred while trying to proxy:')) { | ||
data.header = 'Backend is not reachable.'; | ||
data.text = | ||
'Please contact your server administrator!\nIs the backend running? Is the backend reachable? Are the proxy settings correct?'; | ||
} | ||
} | ||
|
||
if (error.status == undefined) { | ||
data = { | ||
header: 'Internal Error', | ||
text: "The server isn't configured correctly or is unavailable at the moment.", | ||
}; | ||
} | ||
|
||
this.openDialog(data); | ||
} | ||
|
||
openCustomErrorDialog(text = ``, header = `Process failed!`) { | ||
this.openDialog({ | ||
header: header, | ||
text: text, | ||
}); | ||
} | ||
|
||
private openDialog(data: any) { | ||
if (this.dialogOpen) { | ||
console.log( | ||
'Another message should be displayed, but is rejected because another error message is still open. It will be displayed here: ' | ||
); | ||
console.log(data); | ||
return; | ||
} | ||
|
||
this.dialogOpen = true; | ||
this.matDialog.open(InformationPopUpComponent, { | ||
data: data, | ||
}); | ||
this.matDialog.afterAllClosed.subscribe(() => { | ||
this.dialogOpen = false; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters