Although it may seem like a simple task, as a newcomer to Angular, I find myself in need of sorting my object alphabetically from an API HTTP Get call.
Below is the service I am using to retrieve data from the API:
getCustomer(key: string, page: number, pageSize: number): Observable<PagedResponse<Customer>> {
return this.http
.get<PagedResponse<Customer>>(environment.UrlApiSubscription + "Customer/" + key + "/" + page + "/" + pageSize, super.GetAuthTokenHeader())
.pipe(
map(super.extract),
catchError(super.serviceError)
)
}
Furthermore, here is my base service implementation:
protected extract(response: any) {
return response || {};
}
protected serviceError(response: Response | any) {
let customError: string[] = [];
if (response instanceof HttpErrorResponse) {
if (response.statusText === "Unknown Error") {
customError.push("Error");
response.error.errors = customError;
}
}
console.error(response);
return throwError(response);
}