Add catch to many request promises

This commit is contained in:
Matteo Gheza 2023-09-04 16:22:40 +02:00
parent 78c9a2c4e0
commit 5553e7b47e
3 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { Component, OnInit, ViewEncapsulation, HostListener } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { ApiClientService } from 'src/app/_services/api-client.service';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'modal-availability-schedule',
@ -51,7 +52,11 @@ export class ModalAvailabilityScheduleComponent implements OnInit {
public isSelecting = false;
constructor(public bsModalRef: BsModalRef, private api: ApiClientService) { }
constructor(
private toastr: ToastrService,
public bsModalRef: BsModalRef,
private api: ApiClientService
) { }
loadSchedules(schedules: any) {
console.log("Loaded schedules", schedules);
@ -68,6 +73,9 @@ export class ModalAvailabilityScheduleComponent implements OnInit {
this.orientation = window.innerHeight > window.innerWidth ? "portrait" : "landscape";
this.api.get("schedules").then((response: any) => {
this.loadSchedules(response);
}).catch((err) => {
if(err.status === 500) throw err;
this.toastr.error("Errore nel caricare la programmazione oraria. Riprova.");
});
}
@ -75,6 +83,9 @@ export class ModalAvailabilityScheduleComponent implements OnInit {
console.log("Selected cells", this.selectedCells);
this.api.post("schedules", {
schedules: this.selectedCells
}).catch((err) => {
if(err.status === 500) throw err;
this.toastr.error("Errore nel salvare la programmazione oraria. Riprova.");
});
this.bsModalRef.hide();
}

View File

@ -92,6 +92,8 @@ export class EditServiceComponent implements OnInit {
patch.crew = patch.crew.map((e: any) => e.pivot.user_id+"");
patch.type = patch.type_id;
this.serviceForm.patchValue(patch);
}).catch((err) => {
this.toastr.error("Errore nel caricare l'intervento. Ricarica la pagina e riprova.");
});
}
console.log(this.serviceId);
@ -99,6 +101,8 @@ export class EditServiceComponent implements OnInit {
this.api.get("list").then((users) => {
this.users = users;
console.log(this.users);
}).catch((err) => {
this.toastr.error("Errore nel caricare la lista degli utenti. Ricarica la pagina e riprova.");
});
this.loadTypes();
}
@ -107,6 +111,8 @@ export class EditServiceComponent implements OnInit {
this.api.get("service_types").then((types) => {
console.log(types);
this.types = types;
}).catch((err) => {
this.toastr.error("Errore nel caricare le tipologie di intervento. Ricarica la pagina e riprova.");
});
}
@ -135,6 +141,8 @@ export class EditServiceComponent implements OnInit {
});
this.loadTypes();
}
}).catch((err) => {
this.toastr.error("Errore nell'aggiungere tipologia di intervento. Riprova.");
});
}

View File

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApiClientService } from 'src/app/_services/api-client.service';
import { ToastrService } from 'ngx-toastr';
import { marker, latLng, tileLayer } from 'leaflet';
@Component({
@ -18,7 +19,11 @@ export class PlaceDetailsComponent implements OnInit {
options = {};
layers: any[] = [];
constructor(private route: ActivatedRoute, private api: ApiClientService) {
constructor(
private route: ActivatedRoute,
private api: ApiClientService,
private toastr: ToastrService
) {
this.route.paramMap.subscribe(params => {
this.id = parseInt(params.get('id') || '');
@ -58,6 +63,8 @@ export class PlaceDetailsComponent implements OnInit {
];
this.place_loaded = true;
}).catch((err) => {
this.toastr.error("Errore nel caricare i dati del luogo. Ricarica la pagina e riprova.");
});
});
}