import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { ok, err, Result } from 'neverthrow'; @Injectable({ providedIn: 'root' }) export class HttpService { constructor(private http:HttpClient) { } async post(url: string, body: any): Promise> { try { const result = await this.http.post(url, body).toPromise() return ok (result as T) } catch (e) { return err(e as HttpErrorResponse) } } async get(url: string): Promise> { try { const result = await this.http.get(url).toPromise() return ok (result as T) } catch (e) { return err(e as HttpErrorResponse) } } async put(url: string, body: any): Promise> { try { const result = await this.http.put(url, body).toPromise() return ok (result as T) } catch (e) { return err(e as HttpErrorResponse) } } async delete(url: string): Promise> { try { const result = await this.http.delete(url).toPromise() return ok (result as T) } catch (e) { return err(e as HttpErrorResponse) } } }