Here is the code snippet that I am working with:
getElements(apiUrl: string): Observable<Element[]> {
return this.httpClient.get<any>(apiUrl + 'test/elements').pipe(
catchError(error => {
if(error.status === StatusCodes.NOT_FOUND){
console.warn(error.status + ': no data found');
}
else {
this.openModalError(error);
}
return throwError(() => error);
})
);
}
The API response can vary between returning a single Element
object or an array of Element
. However, my function should always return an array. How can I handle converting Element
to an array when necessary?