mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Only log errors for DspaceRestService.get
When refactoring to meet the rxjs/no-implicit-any-catch ESLint rule, I'd made it so errors were logged for DspaceRestService.request calls as well, making it a lot more noisy The console.log in .get is explicitly required by tests though
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
HttpErrorResponse,
|
HttpErrorResponse,
|
||||||
HttpHeaders,
|
HttpHeaders,
|
||||||
HttpParams,
|
HttpParams,
|
||||||
|
HttpResponse,
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
@@ -53,7 +54,21 @@ export class DspaceRestService {
|
|||||||
* An Observable<string> containing the response from the server
|
* An Observable<string> containing the response from the server
|
||||||
*/
|
*/
|
||||||
get(absoluteURL: string): Observable<RawRestResponse> {
|
get(absoluteURL: string): Observable<RawRestResponse> {
|
||||||
return this.request(RestRequestMethod.GET, absoluteURL);
|
const requestOptions = {
|
||||||
|
observe: 'response' as any,
|
||||||
|
headers: new HttpHeaders({ 'Content-Type': DEFAULT_CONTENT_TYPE }),
|
||||||
|
};
|
||||||
|
return this.http.get(absoluteURL, requestOptions).pipe(
|
||||||
|
map((res: HttpResponse<any>) => ({
|
||||||
|
payload: res.body,
|
||||||
|
statusCode: res.status,
|
||||||
|
statusText: res.statusText,
|
||||||
|
})),
|
||||||
|
catchError((err: unknown) => observableThrowError(() => {
|
||||||
|
console.log('Error: ', err);
|
||||||
|
return this.handleHttpError(err);
|
||||||
|
})),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,20 +125,7 @@ export class DspaceRestService {
|
|||||||
statusText: res.statusText,
|
statusText: res.statusText,
|
||||||
})),
|
})),
|
||||||
catchError((err: unknown) => observableThrowError(() => {
|
catchError((err: unknown) => observableThrowError(() => {
|
||||||
console.log('Error: ', err);
|
return this.handleHttpError(err);
|
||||||
if (err instanceof HttpErrorResponse) {
|
|
||||||
const error = new RequestError(
|
|
||||||
(isNotEmpty(err?.error?.message)) ? err.error.message : err.message,
|
|
||||||
);
|
|
||||||
|
|
||||||
error.statusCode = err.status;
|
|
||||||
error.statusText = err.statusText;
|
|
||||||
|
|
||||||
return error;
|
|
||||||
} else {
|
|
||||||
console.error('Cannot construct RequestError from', err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -149,4 +151,20 @@ export class DspaceRestService {
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected handleHttpError(err: unknown): RequestError | unknown {
|
||||||
|
if (err instanceof HttpErrorResponse) {
|
||||||
|
const error = new RequestError(
|
||||||
|
(isNotEmpty(err?.error?.message)) ? err.error.message : err.message,
|
||||||
|
);
|
||||||
|
|
||||||
|
error.statusCode = err.status;
|
||||||
|
error.statusText = err.statusText;
|
||||||
|
|
||||||
|
return error;
|
||||||
|
} else {
|
||||||
|
console.error('Cannot construct RequestError from', err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user