[#1] Add error notification when an error attempts when post saving.

This commit is contained in:
2019-08-08 20:59:17 +02:00
parent 8205168bce
commit e7583a59c2
2 changed files with 8 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/c
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AuthService } from '../services/auth.service';
import { NotificationsComponent } from '../notifications/notifications.component';
@Injectable()
export class UnauthorizedInterceptor implements HttpInterceptor {
@@ -17,6 +18,7 @@ export class UnauthorizedInterceptor implements HttpInterceptor {
if (err.status === 401) {
this.authService.setAnonymous();
this.router.navigate(['/login']);
window.setTimeout(() => NotificationsComponent.error('Veuillez vous authentifier pour réaliser cette action.'), 500);
}
const error = (err.error && err.error.message) || err.statusText;

View File

@@ -160,10 +160,16 @@ export class CreateUpdatePostComponent implements OnInit {
if (this.model.key) {
this.createUpdatePostService.updatePost(this.model).subscribe(post => {
NotificationsComponent.success('Modification enregistrée');
}, error => {
console.log(error);
NotificationsComponent.error('Une erreur est survenue lors de l\'enregistrement des modifications.');
});
} else {
this.createUpdatePostService.addPost(this.model).subscribe(post => {
this.router.navigate([`/posts/update/${post.key}`]);
}, error => {
console.log(error);
NotificationsComponent.error('Une erreur est survenue lors de la création du post.');
});
}
} else {