31 lines
1005 B
TypeScript
31 lines
1005 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
|
import { ApiResponse } from '../models/route.model';
|
|
import { environment } from '../../../environments/environment';
|
|
import { catchError, timeout, throwError } from 'rxjs';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class RutasService {
|
|
|
|
constructor(private http: HttpClient) { }
|
|
|
|
calcularRutas(data: FormData) {
|
|
return this.http.post<ApiResponse>(
|
|
environment.n8nWebhookUrl,
|
|
data
|
|
).pipe(
|
|
timeout(environment.requestTimeoutMs),
|
|
catchError((err: HttpErrorResponse | Error) => {
|
|
if (err instanceof Error && err.name === 'TimeoutError') {
|
|
return throwError(() => Object.assign(new Error('Timeout al calcular rutas (30s). Intenta con menos filas o reintenta.'), { name: 'TimeoutError' }));
|
|
}
|
|
return throwError(() => err);
|
|
})
|
|
);
|
|
}
|
|
|
|
reoptimizarRutas(data: FormData) {
|
|
return this.calcularRutas(data);
|
|
}
|
|
}
|