Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
import { Injectable } from '@angular/core'; import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; export interface Organization { code: string, manager: string, fullName: string, name: string, address: string, activity: string, status: string } @Injectable({ providedIn: 'root' }) export class UfopService { private baseUrl = 'http://авава'; private token = 'вавв'; constructor(private http: HttpClient) {} getOrganization(code: string) { // const code = '23788893'; const headers = new HttpHeaders({ Token: this.token }) return this.http.get<Organization | null>(`${this.baseUrl}/organizations/${code}`, { headers }).pipe( catchError(this.handleError) ); } private handleError(error: HttpErrorResponse): Observable<never> { if (error.error instanceof ErrorEvent) { console.error('An error occurred:', error.error.message); } else { console.error( `Backend returned code ${error.status}, ` + `body was: ${error.error}`); } return throwError('Something bad happened; please try again later.'); } }