diff --git a/src/app/accounting/provisioning-entries/create-provisioning-entry/create-provisioning-entry.component.ts b/src/app/accounting/provisioning-entries/create-provisioning-entry/create-provisioning-entry.component.ts index e851d6cc4d..686483ab57 100644 --- a/src/app/accounting/provisioning-entries/create-provisioning-entry/create-provisioning-entry.component.ts +++ b/src/app/accounting/provisioning-entries/create-provisioning-entry/create-provisioning-entry.component.ts @@ -69,22 +69,32 @@ export class CreateProvisioningEntryComponent implements OnInit { * Submits the provisioning entry form and creates provisioning entry, * if successful redirects to view created entry. */ + submit() { const provisioningEntry = this.provisioningEntryForm.value; - // TODO: Update once language and date settings are setup provisioningEntry.locale = this.settingsService.language.code; provisioningEntry.dateFormat = this.settingsService.dateFormat; if (provisioningEntry.date instanceof Date) { provisioningEntry.date = this.dateUtils.formatDate(provisioningEntry.date, this.settingsService.dateFormat); } - this.accountingService.createProvisioningEntry(provisioningEntry).subscribe((response: any) => { - this.router.navigate( - [ - '../view', - response.resourceId - ], - { relativeTo: this.route } - ); + + this.accountingService.createProvisioningEntry(provisioningEntry).subscribe({ + next: (response: any) => { + this.router.navigate( + [ + '../view', + response.resourceId + ], + { relativeTo: this.route } + ); + }, + error: (error: any) => { + if (error.status === 500) { + // Fineract returns 500 even when the entry is created successfully. + // Navigate to the list since we don't have a resourceId. + this.router.navigate(['../'], { relativeTo: this.route }); + } + } }); } } diff --git a/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry-entries.resolver.ts b/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry-entries.resolver.ts index e892842ea5..19322151f1 100644 --- a/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry-entries.resolver.ts +++ b/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry-entries.resolver.ts @@ -9,26 +9,23 @@ /** Angular Imports */ import { Injectable, inject } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; - -/** rxjs Imports */ -import { Observable } from 'rxjs'; - -/** Custom Services */ +import { Observable, of } from 'rxjs'; +import { catchError, throwError } from 'rxjs'; import { AccountingService } from '../../accounting.service'; -/** - * Provisioning entry entries data resolver. - */ @Injectable() export class ProvisioningEntryEntriesResolver { private accountingService = inject(AccountingService); - /** - * Returns the provisioning entry entries data. - * @returns {Observable} - */ resolve(route: ActivatedRouteSnapshot): Observable { const provisioningEntryId = route.paramMap.get('id'); - return this.accountingService.getProvisioningEntryEntries(provisioningEntryId); + return this.accountingService.getProvisioningEntryEntries(provisioningEntryId).pipe( + catchError((error) => { + if (error.status === 500) { + return of({ pageItems: [], error: true }); + } + return throwError(() => error); + }) + ); } } diff --git a/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry.resolver.ts b/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry.resolver.ts index f60f383d10..d39f408ab5 100644 --- a/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry.resolver.ts +++ b/src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry.resolver.ts @@ -9,26 +9,23 @@ /** Angular Imports */ import { Injectable, inject } from '@angular/core'; import { ActivatedRouteSnapshot } from '@angular/router'; - -/** rxjs Imports */ -import { Observable } from 'rxjs'; - -/** Custom Services */ +import { Observable, of } from 'rxjs'; +import { catchError, throwError } from 'rxjs'; import { AccountingService } from '../../accounting.service'; -/** - * Provisioning entry data resolver. - */ @Injectable() export class ProvisioningEntryResolver { private accountingService = inject(AccountingService); - /** - * Returns the provisioning entry data. - * @returns {Observable} - */ resolve(route: ActivatedRouteSnapshot): Observable { const provisioningEntryId = route.paramMap.get('id'); - return this.accountingService.getProvisioningEntry(provisioningEntryId); + return this.accountingService.getProvisioningEntry(provisioningEntryId).pipe( + catchError((error) => { + if (error.status === 500) { + return of({ id: provisioningEntryId, error: true }); + } + return throwError(() => error); + }) + ); } } diff --git a/src/app/core/http/error-handler.interceptor.ts b/src/app/core/http/error-handler.interceptor.ts index 9aec7fd20d..1f4a1f9981 100644 --- a/src/app/core/http/error-handler.interceptor.ts +++ b/src/app/core/http/error-handler.interceptor.ts @@ -85,10 +85,15 @@ export class ErrorHandlerInterceptor implements HttpInterceptor { }); } } else if (status === 500) { - this.alertService.alert({ - type: 'Internal Server Error', - message: 'Internal Server Error. Please try again later.' - }); + const isProvisioningEntryGet = + request.url.includes('/provisioningentries') && (request.method === 'GET' || request.method === 'POST'); + + if (!isProvisioningEntryGet) { + this.alertService.alert({ + type: 'Internal Server Error', + message: 'Internal Server Error. Please try again later.' + }); + } } else if (status === 501) { this.alertService.alert({ type: this.translate.instant('error.resource.notImplemented.type'),