My objective is to retrieve data, store it, and return either true or false based on the operation outcome. Initially, I attempted to make the call and then use return of(true) to create an observable. The method I have is as follows.
setValidations(): Observable<boolean> {
...
this.http.get<Validation[]>(url)
.subscribe(
suc => {
environment.validations = suc;
return of(true);
},
err => of(false)
);
}
The error message informs me that I need to return something of type Observable. This leads me to believe that there might be a syntax issue. How can I correct this?
Edit based on answers/comments
setValidations(): Observable<boolean> {
...
return this.http.get<Validation>(url)
.pipe(
map(_ => { console.log("Success"); return of(true); }),
catchError => { console.log("Error"); return of(false); }
);
}
I revised the method as demonstrated above. It appears to function properly, but I am receiving a warning about a variable named catchError being shadowed. This raises concerns that my approach may not be optimal.