I have the following code:
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);
})
);
}
Depending on apiUrl
, API will return either Element
or Element[]
. But I want my function to always return an array. How can I convert Element
to an array when it isn't?