aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/error-bar/error-bar.component.ts
blob: 277552b9bc537b9a2ac18170599d05e07e1318fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-error-bar',
  templateUrl: './error-bar.component.html',
  styleUrls: ['./error-bar.component.css']
})
export class ErrorBarComponent implements OnInit {
  public errorMsg = '';

  constructor()
  { }

  ngOnInit(): void {
    this.hideError();
  }

  showError(error: HttpErrorResponse): void {
    this.errorMsg = '';

    const errors: string[][] = Object.values(Object.values(error.error)[0] as any);

    for (const errorArr of errors) {
      for (const errorMsg of errorArr) {
        this.errorMsg += errorMsg + '\n';
      }
    }
  }

  hideError(): void {
    this.errorMsg = '';
  }
}