Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lakhoune committed Aug 10, 2022
1 parent fa0e4f5 commit ce1d4a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 8 additions & 7 deletions angular-cards/src/app/services/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { Observable, BehaviorSubject } from 'rxjs';
import { Notification, WarnMessage, InfoMessage } from '../models/Notification';
import { Router } from '@angular/router';
import { HttpErrorResponse } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
@Injectable({
providedIn: 'root',
})
export class NotificationsService {
private notifications$ = new BehaviorSubject<Notification[]>([]);
constructor(private router: Router) {}
constructor(private router: Router, private translate: TranslateService) {}

addNotification(n: Notification) {
setTimeout(() => {
Expand Down Expand Up @@ -88,17 +89,17 @@ export class NotificationsService {
}
break;
case 500:
this.addNotification(
new WarnMessage('Der Server scheint offline zu sein. Versuche es später erneut.', error.status)
);
let message =
this.translate.instant('notifications.server-offline') + ' ' + this.translate.instant('check-later');
this.addNotification(new WarnMessage(message, error.status));
this.router.navigateByUrl('/');
break;
case 504:
this.addNotification(
new WarnMessage('Der Server scheint offline zu sein. Versuche es später erneut.', error.status)
);
message = this.translate.instant('notifications.server-offline') + ' ' + this.translate.instant('check-later');
this.addNotification(new WarnMessage(message, error.status));
break;
default:
message = this.translate.instant('notifications.unknown-error') + ' ' + this.translate.instant('check-later');
this.addNotification(
new WarnMessage('Ein unbekannter Fehler ist aufgetreten. Versuche es später erneut.', error.status)
);
Expand Down
5 changes: 4 additions & 1 deletion angular-cards/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@
"notifications": {
"notifications": "Benachrichtigungen",
"add-card-success": "Deine Karte wurde erfolgreich hinzugefügt.",
"pick-up": "Möchtest du zu deiner zuletzt besuchten Karte zurückkehren?"
"pick-up": "Möchtest du zu deiner zuletzt besuchten Karte zurückkehren?",
"server-offline": "Der Server scheint offline zu sein.",
"check-later": "Versuche es später erneut.",
"unknown-error": "Ein unbekannter Fehler ist aufgetreten."
},
"report-type": "Report Typ",
"users": "Nutzer",
Expand Down
5 changes: 4 additions & 1 deletion angular-cards/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@
"notifications": {
"notifications": "Notifications",
"add-card-success": "Your card has been added successfully",
"pick-up": "Do you want to pick up where you left off?"
"pick-up": "Do you want to pick up where you left off?",
"server-offline": "The server is offline.",
"check-later": "Please try again later.",
"unknown-error": "An unknown error occured."
},
"users": "Users",
"number-of-cards": "Number of cards",
Expand Down

0 comments on commit ce1d4a1

Please sign in to comment.