Skip to content

Instantly share code, notes, and snippets.

@davistran86
Last active August 18, 2022 13:02
Show Gist options
  • Save davistran86/4b36341ac36e474212788e854a02db59 to your computer and use it in GitHub Desktop.
Save davistran86/4b36341ac36e474212788e854a02db59 to your computer and use it in GitHub Desktop.
import { catchError, map } from 'rxjs/operators';

const response = this.httpService
  .get('https://abc.com/api/v2/branches')
  .pipe(
    map((response) => response.data),
    catchError((e) => {
      throw new HttpException(e.response.data, e.response.status);
    }),
  );

return response;
@davistran86
Copy link
Author

With promise

const response = await this.httpService
  .get('https://abc.com/api/v2/branches')
  .toPromise()
  .catch((err) => {
    throw new HttpException(err.response.data, err.response.status);
  });

return response.data;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment