From 677ed3dfd025336081ca2a6021e77c52b8f4dc40 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 17 Jun 2021 20:07:02 +0200 Subject: [PATCH] use token to auth at api --- hv2-ui/src/app/config.ts | 1 + hv2-ui/src/app/error-handler.interceptor.ts | 3 +-- hv2-ui/src/app/test-output.service.ts | 5 +++-- hv2-ui/src/app/test-output/test-output.component.html | 6 +++++- hv2-ui/src/app/test-output/test-output.component.ts | 3 ++- hv2-ui/src/app/testOutput.ts | 4 ++++ 6 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 hv2-ui/src/app/testOutput.ts diff --git a/hv2-ui/src/app/config.ts b/hv2-ui/src/app/config.ts index f3b9396..65c4d0e 100644 --- a/hv2-ui/src/app/config.ts +++ b/hv2-ui/src/app/config.ts @@ -1 +1,2 @@ export const serviceBaseUrl = "https://api.hv.nober.de"; +// export const serviceBaseUrl = "http://172.16.10.38:5000"; diff --git a/hv2-ui/src/app/error-handler.interceptor.ts b/hv2-ui/src/app/error-handler.interceptor.ts index d7c1476..e09b662 100644 --- a/hv2-ui/src/app/error-handler.interceptor.ts +++ b/hv2-ui/src/app/error-handler.interceptor.ts @@ -19,10 +19,9 @@ export class ErrorHandlerInterceptor implements HttpInterceptor { intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe( catchError((errorResponse: HttpErrorResponse) => { + this.messageService.add(`Intercepted http error: ${errorResponse}`) if (errorResponse.status === 401) { this.router.navigateByUrl('/login') - } else { - this.messageService.add(`Intercepted http error: ${errorResponse}`) } return throwError(errorResponse) }) diff --git a/hv2-ui/src/app/test-output.service.ts b/hv2-ui/src/app/test-output.service.ts index 365dea9..954c23b 100644 --- a/hv2-ui/src/app/test-output.service.ts +++ b/hv2-ui/src/app/test-output.service.ts @@ -4,6 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { MessageService } from './message.service'; import { serviceBaseUrl } from './config'; +import { TestOutput } from './testOutput'; @Injectable({ providedIn: 'root' @@ -11,8 +12,8 @@ import { serviceBaseUrl } from './config'; export class TestOutputService { constructor(private messageService: MessageService, private http: HttpClient) { } - getTestOutput(): Promise { + getTestOutput(): Promise { this.messageService.add(`TestOutputService: fetch test output`); - return this.http.get(`${serviceBaseUrl}/v1/test`).toPromise() + return this.http.get(`${serviceBaseUrl}/v1/test`).toPromise() } } diff --git a/hv2-ui/src/app/test-output/test-output.component.html b/hv2-ui/src/app/test-output/test-output.component.html index cd7acb4..1e8ae66 100644 --- a/hv2-ui/src/app/test-output/test-output.component.html +++ b/hv2-ui/src/app/test-output/test-output.component.html @@ -9,7 +9,11 @@

Mein Test

-
{{testOutput}}
+
+                    {{testOutput.message}}
+                
+                    {{testOutput.details}}
+                
diff --git a/hv2-ui/src/app/test-output/test-output.component.ts b/hv2-ui/src/app/test-output/test-output.component.ts index da63c85..37a20b2 100644 --- a/hv2-ui/src/app/test-output/test-output.component.ts +++ b/hv2-ui/src/app/test-output/test-output.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { MessageService } from '../message.service'; import { TestOutputService } from '../test-output.service'; +import { TestOutput } from '../testOutput'; @Component({ selector: 'app-test-output', @@ -11,7 +12,7 @@ export class TestOutputComponent implements OnInit { constructor(private testOutputService: TestOutputService, private messageService: MessageService) { } - testOutput : String + testOutput : TestOutput = { "message": "abc", "details": "123" } async getTestOutput() { try { diff --git a/hv2-ui/src/app/testOutput.ts b/hv2-ui/src/app/testOutput.ts new file mode 100644 index 0000000..65e239e --- /dev/null +++ b/hv2-ui/src/app/testOutput.ts @@ -0,0 +1,4 @@ +export interface TestOutput { + message: string + details: string +}