Currently, I am facing an issue while trying to retrieve a JSON file for my memory card game. Even after following the solution provided in this question: How to get json file from HttpClient?, I encounter an error message that is quite confusing for me: https://i.sstatic.net/ROkRe.png
Although my code mirrors the one mentioned in the previous answer, it seems that something might have changed over the past 3 years, causing it to break. Any ideas on what could be causing this issue and how can it be resolved? Additionally, I would like to know the most efficient way of retrieving JSON data from a server using Angular.
Wishing everyone a wonderful day!
For reference, here are the relevant parts of my code:
const httpOptions = {
headers: new HttpHeaders({ "Content-Type": "application/json", "Authorization": "c31z" })
};
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error("An error occurred:", error.error.message);
} else {
// The backend returned an unsuccessful response code. The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` + `body was: ${error.error}`
);
}
// return an observable with a user-facing error message
return throwError(error);
}
private extractData(res: Response) {
let body = res;
return body || {};
}
public getListOfGroup(url: string): Observable<any> {
// Call the http GET
return this.http.get(url,httpOptions).pipe(map(this.extractData),catchError(this.handleError)
);
}