I want to show a toast that will have text depending upon the status code of the HTTP response. code from service:-
private options = {
headers: new HttpHeaders()
.set("Content-Type", "application/json")
.set("x-app-id", this.appId)
.set("x-app-key", this.appKey)
.set("observe","response")
};
constructor(private http: HttpClient) {}
search(query: string): Observable<{}> {
return this.http.post(this.url, {query: query}, this.options)
}
and this is what I am doing in frontend:-
search() {
this.showcard = false;
this.isLoading = true;
this.nutrix.search(this.searchValue).subscribe((res) => {
if(res){
this.isLoading = false;
this.showcard = true;
this.queryResult = res["foods"][0];
this.imageUrl = this.queryResult['photo']['thumb']
}
console.log(this.queryResult);
},(error) => {
console.log(error);
this.isLoading = false;
});
}
It`s better to use Error handling with interceptor
add this tag in app.module.ts