In the codebase I am currently working on, I came across a backend service that I would like to utilize for logging all errors along with their corresponding Http statuses. If possible, I also want to retrieve the full stack trace of these errors from this backend service. The following code snippet presents an example of how the backend service is being used. This is my first experience working with cloud functions.
backend.service.ts
import { Injectable } from '@angular/core';
import { AngularFireFunctions } from '@angular/fire/compat/functions';
/**
* Interface with the firebase backend.
*/
@Injectable({ providedIn: 'root' })
export class BackendService
{
constructor(private _fns: AngularFireFunctions) { }
/**
* Call Firebase Cloud Function
*
* @param fName: Function Name
* @param params: Function Parameter Object
*/
callFunction(fName: string, params: any) {
const toCall = this._fns.httpsCallable(fName);
// log errors here
return toCall(params)
}
}
Using backend service
import { Injectable } from '@angular/core';
import { Provision, WriteProvisionCommand } from '@s4y/model/accounting/provisions';
import { BackendService } from '@bxy/utils/ngxfm/angular';
import { DbMethods } from '@bxy/model/data/db';
@Injectable()
export class RequestWithSettlementService
{
constructor(private _backend: BackendService)
{}
deleteBill = (propId: string, tr: FTransactionRequest) => this.deleteProvision(propId, tr as any as Provision);
deleteProvision(propId: string, tr: FTransactionRequest)
{
const call: WriteProvisionCommand = {
provision: tr,
propId,
method: DbMethods.DELETE
};
return this._backend.callFunction('writeProvision', call);
}
}