|
| 1 | +import { HttpClient } from '@angular/common/http'; |
| 2 | +import { Component, inject } from '@angular/core'; |
| 3 | +import { MatButton } from '@angular/material/button'; |
| 4 | + |
| 5 | +@Component({ |
| 6 | + selector: 'app-test-error', |
| 7 | + imports: [ |
| 8 | + MatButton |
| 9 | + ], |
| 10 | + templateUrl: './test-error.component.html', |
| 11 | + styleUrl: './test-error.component.scss' |
| 12 | +}) |
| 13 | +export class TestErrorComponent { |
| 14 | + baseUrl = 'https://localhost:5001/api/'; |
| 15 | + private http = inject(HttpClient); |
| 16 | + validationErrors?: string[]; |
| 17 | + |
| 18 | + get404Error() { |
| 19 | + this.http.get(this.baseUrl + 'buggy/notfound').subscribe({ |
| 20 | + next: response => console.log(response), |
| 21 | + error: error => console.log(error) |
| 22 | + }) |
| 23 | + } |
| 24 | + |
| 25 | + get400Error() { |
| 26 | + this.http.get(this.baseUrl + 'buggy/badrequest').subscribe({ |
| 27 | + next: response => console.log(response), |
| 28 | + error: error => console.log(error) |
| 29 | + }) |
| 30 | + } |
| 31 | + |
| 32 | + get401Error() { |
| 33 | + this.http.get(this.baseUrl + 'buggy/unauthorized').subscribe({ |
| 34 | + next: response => console.log(response), |
| 35 | + error: error => console.log(error) |
| 36 | + }) |
| 37 | + } |
| 38 | + |
| 39 | + get500Error() { |
| 40 | + this.http.get(this.baseUrl + 'buggy/internalerror').subscribe({ |
| 41 | + next: response => console.log(response), |
| 42 | + error: error => console.log(error) |
| 43 | + }) |
| 44 | + } |
| 45 | + |
| 46 | + get400ValidationErrorError() { |
| 47 | + this.http.post(this.baseUrl + 'buggy/validationerror', {}).subscribe({ |
| 48 | + next: response => console.log(response), |
| 49 | + error: error => this.validationErrors = error |
| 50 | + }) |
| 51 | + } |
| 52 | +} |
0 commit comments