Skip to content

Commit 6052d17

Browse files
committed
fix(WEB-370): handle Fineract 500 errors gracefully for provisioning entries
1 parent 7a9c25e commit 6052d17

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed

src/app/accounting/provisioning-entries/create-provisioning-entry/create-provisioning-entry.component.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,32 @@ export class CreateProvisioningEntryComponent implements OnInit {
6969
* Submits the provisioning entry form and creates provisioning entry,
7070
* if successful redirects to view created entry.
7171
*/
72+
7273
submit() {
7374
const provisioningEntry = this.provisioningEntryForm.value;
74-
// TODO: Update once language and date settings are setup
7575
provisioningEntry.locale = this.settingsService.language.code;
7676
provisioningEntry.dateFormat = this.settingsService.dateFormat;
7777
if (provisioningEntry.date instanceof Date) {
7878
provisioningEntry.date = this.dateUtils.formatDate(provisioningEntry.date, this.settingsService.dateFormat);
7979
}
80-
this.accountingService.createProvisioningEntry(provisioningEntry).subscribe((response: any) => {
81-
this.router.navigate(
82-
[
83-
'../view',
84-
response.resourceId
85-
],
86-
{ relativeTo: this.route }
87-
);
80+
81+
this.accountingService.createProvisioningEntry(provisioningEntry).subscribe({
82+
next: (response: any) => {
83+
this.router.navigate(
84+
[
85+
'../view',
86+
response.resourceId
87+
],
88+
{ relativeTo: this.route }
89+
);
90+
},
91+
error: (error: any) => {
92+
if (error.status === 500) {
93+
// Fineract returns 500 even when the entry is created successfully.
94+
// Navigate to the list since we don't have a resourceId.
95+
this.router.navigate(['../'], { relativeTo: this.route });
96+
}
97+
}
8898
});
8999
}
90100
}

src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry-entries.resolver.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,18 @@
99
/** Angular Imports */
1010
import { Injectable, inject } from '@angular/core';
1111
import { ActivatedRouteSnapshot } from '@angular/router';
12-
13-
/** rxjs Imports */
14-
import { Observable } from 'rxjs';
15-
16-
/** Custom Services */
12+
import { Observable, of } from 'rxjs';
13+
import { catchError } from 'rxjs/operators';
1714
import { AccountingService } from '../../accounting.service';
1815

19-
/**
20-
* Provisioning entry entries data resolver.
21-
*/
2216
@Injectable()
2317
export class ProvisioningEntryEntriesResolver {
2418
private accountingService = inject(AccountingService);
2519

26-
/**
27-
* Returns the provisioning entry entries data.
28-
* @returns {Observable<any>}
29-
*/
3020
resolve(route: ActivatedRouteSnapshot): Observable<any> {
3121
const provisioningEntryId = route.paramMap.get('id');
32-
return this.accountingService.getProvisioningEntryEntries(provisioningEntryId);
22+
return this.accountingService
23+
.getProvisioningEntryEntries(provisioningEntryId)
24+
.pipe(catchError(() => of({ pageItems: [], error: true })));
3325
}
3426
}

src/app/accounting/provisioning-entries/view-provisioning-entry/provisioning-entry.resolver.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,18 @@
99
/** Angular Imports */
1010
import { Injectable, inject } from '@angular/core';
1111
import { ActivatedRouteSnapshot } from '@angular/router';
12-
13-
/** rxjs Imports */
14-
import { Observable } from 'rxjs';
15-
16-
/** Custom Services */
12+
import { Observable, of } from 'rxjs';
13+
import { catchError } from 'rxjs/operators';
1714
import { AccountingService } from '../../accounting.service';
1815

19-
/**
20-
* Provisioning entry data resolver.
21-
*/
2216
@Injectable()
2317
export class ProvisioningEntryResolver {
2418
private accountingService = inject(AccountingService);
2519

26-
/**
27-
* Returns the provisioning entry data.
28-
* @returns {Observable<any>}
29-
*/
3020
resolve(route: ActivatedRouteSnapshot): Observable<any> {
3121
const provisioningEntryId = route.paramMap.get('id');
32-
return this.accountingService.getProvisioningEntry(provisioningEntryId);
22+
return this.accountingService
23+
.getProvisioningEntry(provisioningEntryId)
24+
.pipe(catchError(() => of({ id: provisioningEntryId, error: true })));
3325
}
3426
}

src/app/core/http/error-handler.interceptor.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
8585
});
8686
}
8787
} else if (status === 500) {
88-
this.alertService.alert({
89-
type: 'Internal Server Error',
90-
message: 'Internal Server Error. Please try again later.'
91-
});
88+
const isProvisioningEntryGet = request.url.includes('/provisioningentries/') && request.method === 'GET';
89+
90+
if (!isProvisioningEntryGet) {
91+
this.alertService.alert({
92+
type: 'Internal Server Error',
93+
message: 'Internal Server Error. Please try again later.'
94+
});
95+
}
9296
} else if (status === 501) {
9397
this.alertService.alert({
9498
type: this.translate.instant('error.resource.notImplemented.type'),

0 commit comments

Comments
 (0)