@angular/common/http#HttpResponseBase TypeScript Examples

The following examples show how to use @angular/common/http#HttpResponseBase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: download.service.ts    From gengen with MIT License 6 votes vote down vote up
private getFileName(httpResponse: HttpResponseBase, saveAs?: string): string {
        if (saveAs) {
            return saveAs;
        }

        const disposition = httpResponse.headers.get('Content-Disposition');
        if (!disposition) {
            return this.defaultFileName;
        }

        const results = this.fileNameRegex.exec(disposition);
        if (!results?.[1]) {
            return this.defaultFileName;
        }

        return results?.[1].replace(/['"]/g, '');
    }
Example #2
Source File: ignore-not-found.ts    From ngx-operators with MIT License 6 votes vote down vote up
/**
 * If the underlying request throws with a 404 error, it will swallow the error
 * and complete the observable instead. All other errors will be rethrown.
 *
 * You can then set a fallback value with `defaultIfEmpty`.
 *
 * @returns stream which will map 404 errors to `undefined`
 * @example
 * this.http.get<User>('/users/123').pipe(
 *   ignoreNotFound()
 * )
 */
export function ignoreNotFound<T>(): (source: Observable<T>) => Observable<T> {
  return (source: Observable<T>): Observable<T> =>
    source.pipe(
      catchError(error => {
        if (error instanceof HttpResponseBase && error.status === 404) {
          return EMPTY;
        }
        return throwError(error);
      })
    );
}