I'm facing an issue with a method that subscribes to an endpoint for a response. In some cases, the endpoint returns null and I need to handle this scenario.
public list: Array<any>;
this.GetList(this.getListRequest)
.subscribe(
(resp) => {
this.progressSpinnerService.stopLoading();
this.list = resp.loanAdjustmentResult.loanAdjustmentList; //error is here
},
(error) => {
this.progressSpinnerService.stopLoading();
this.handleServiceError(error); // error handling.
this.serviceError = true;
}
);
The response from the service has the following structure:
{
"header":{
"statuscode":"0",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
"wfpt":null,
"paginationContext":null,
"reasonCode":null
},
"accountNumber":null,
"loanAdjustmentResult":null
}
I'm encountering an ERROR
TypeError: Cannot read property 'loanAdjustmentList' of null
at the line mentioned above. Any suggestions on how to handle this error?