use token to auth at api
This commit is contained in:
@ -1 +1,2 @@
|
|||||||
export const serviceBaseUrl = "https://api.hv.nober.de";
|
export const serviceBaseUrl = "https://api.hv.nober.de";
|
||||||
|
// export const serviceBaseUrl = "http://172.16.10.38:5000";
|
||||||
|
@ -19,10 +19,9 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
|
|||||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||||
return next.handle(request).pipe(
|
return next.handle(request).pipe(
|
||||||
catchError((errorResponse: HttpErrorResponse) => {
|
catchError((errorResponse: HttpErrorResponse) => {
|
||||||
|
this.messageService.add(`Intercepted http error: ${errorResponse}`)
|
||||||
if (errorResponse.status === 401) {
|
if (errorResponse.status === 401) {
|
||||||
this.router.navigateByUrl('/login')
|
this.router.navigateByUrl('/login')
|
||||||
} else {
|
|
||||||
this.messageService.add(`Intercepted http error: ${errorResponse}`)
|
|
||||||
}
|
}
|
||||||
return throwError(errorResponse)
|
return throwError(errorResponse)
|
||||||
})
|
})
|
||||||
|
@ -4,6 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|||||||
|
|
||||||
import { MessageService } from './message.service';
|
import { MessageService } from './message.service';
|
||||||
import { serviceBaseUrl } from './config';
|
import { serviceBaseUrl } from './config';
|
||||||
|
import { TestOutput } from './testOutput';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -11,8 +12,8 @@ import { serviceBaseUrl } from './config';
|
|||||||
export class TestOutputService {
|
export class TestOutputService {
|
||||||
constructor(private messageService: MessageService, private http: HttpClient) { }
|
constructor(private messageService: MessageService, private http: HttpClient) { }
|
||||||
|
|
||||||
getTestOutput(): Promise<String> {
|
getTestOutput(): Promise<TestOutput> {
|
||||||
this.messageService.add(`TestOutputService: fetch test output`);
|
this.messageService.add(`TestOutputService: fetch test output`);
|
||||||
return this.http.get<String>(`${serviceBaseUrl}/v1/test`).toPromise()
|
return this.http.get<TestOutput>(`${serviceBaseUrl}/v1/test`).toPromise()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,11 @@
|
|||||||
<div>
|
<div>
|
||||||
|
|
||||||
<h2>Mein Test</h2>
|
<h2>Mein Test</h2>
|
||||||
<pre>{{testOutput}}</pre>
|
<pre>
|
||||||
|
{{testOutput.message}}
|
||||||
|
|
||||||
|
{{testOutput.details}}
|
||||||
|
</pre>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { MessageService } from '../message.service';
|
import { MessageService } from '../message.service';
|
||||||
import { TestOutputService } from '../test-output.service';
|
import { TestOutputService } from '../test-output.service';
|
||||||
|
import { TestOutput } from '../testOutput';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-test-output',
|
selector: 'app-test-output',
|
||||||
@ -11,7 +12,7 @@ export class TestOutputComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private testOutputService: TestOutputService, private messageService: MessageService) { }
|
constructor(private testOutputService: TestOutputService, private messageService: MessageService) { }
|
||||||
|
|
||||||
testOutput : String
|
testOutput : TestOutput = { "message": "abc", "details": "123" }
|
||||||
|
|
||||||
async getTestOutput() {
|
async getTestOutput() {
|
||||||
try {
|
try {
|
||||||
|
4
hv2-ui/src/app/testOutput.ts
Normal file
4
hv2-ui/src/app/testOutput.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface TestOutput {
|
||||||
|
message: string
|
||||||
|
details: string
|
||||||
|
}
|
Reference in New Issue
Block a user