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 = "http://172.16.10.38:5000";
|
||||
|
@ -19,10 +19,9 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
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)
|
||||
})
|
||||
|
@ -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<String> {
|
||||
getTestOutput(): Promise<TestOutput> {
|
||||
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>
|
||||
|
||||
<h2>Mein Test</h2>
|
||||
<pre>{{testOutput}}</pre>
|
||||
<pre>
|
||||
{{testOutput.message}}
|
||||
|
||||
{{testOutput.details}}
|
||||
</pre>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -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 {
|
||||
|
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