Skip to content

Commit

Permalink
feat: added head requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lem-onade committed Apr 14, 2020
1 parent e0f59de commit cef81e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ export class DGTHttpAngularService extends DGTHttpService {
);
}

public head<T>(uri: string, headers?: { [key: string]: string }): Observable<DGTHttpResponse<T>> {
this.logger.debug(DGTHttpAngularService.name, 'Sending HEAD request', {uri});

return this.http.head(uri, {headers, observe: 'response'})
.pipe(
map(response => ({
data: response.body as T,
success: true,
status: response.status
})),
catchError(error => of(this.handleError<T>(error))),
);
}

private handleError<T>(error: HttpErrorResponse): DGTHttpResponse<T> {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export abstract class DGTHttpService {
public abstract patch<T>(uri: string, body: any, headers?: { [key: string]: string }): Observable<DGTHttpResponse<T>>;
public abstract post<T>(uri: string, body: any, headers?: { [key: string]: string }): Observable<DGTHttpResponse<T>>;
public abstract put<T>(uri: string, body: any, headers?: { [key: string]: string }): Observable<DGTHttpResponse<T>>;
public abstract head<T>(uri: string, headers?: { [key: string]: string }): Observable<DGTHttpResponse<T>>;
}

0 comments on commit cef81e6

Please sign in to comment.