Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
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);
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
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);
})
);
}
}
13 changes: 9 additions & 4 deletions src/app/core/http/error-handler.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this piece of code reduce the possibility to catch the error in another endpoints or methods

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right to flag this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is intentionally scoped very narrowly, it only suppresses the toast for requests to /provisioningentries/ with GET or POST methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other endpoints and methods will still trigger the global error toast as normal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think isClientImage404 uses this same pattern which is already in the codebase


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'),
Expand Down
Loading