import { APIURLHEADER, ERRORDATA } from 'CommonModel';
import * as HttpStatus from 'http-status-codes';
import { Observable } from 'rxjs';
-import { isNullOrUndefined } from 'util';
/**
* An Injectable is a class adorned with the @Injectable decorator function.
private http: HttpClient;
/** API URL. Disabled tslint since server doesn't support https protocol */
private apiURL: string = '';
+ /** Method to handle null or undefined @private */
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ private isNullOrUndefined = (data: any): boolean => data === null || data === undefined;
/** Notifier service to popup notification @private */
private notifierService: NotifierService;
/** Instance for active modal service @public */
public getResource(apiURL: string, httpHeaders?: { headers: HttpHeaders }): Observable<{}> {
const getRequest: APIURLHEADER = this.getHttpoptions(apiURL);
- if (!isNullOrUndefined(httpHeaders)) {
+ if (!this.isNullOrUndefined(httpHeaders)) {
return this.http.get(apiURL, httpHeaders);
} else {
return this.http.get(getRequest.url, getRequest.httpOptions);
public postResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable<{}> {
const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url);
- if (!isNullOrUndefined(apiURLHeader.httpOptions)) {
+ if (!this.isNullOrUndefined(apiURLHeader.httpOptions)) {
return this.http.post(apiURLHeader.url, payload, apiURLHeader.httpOptions);
} else {
return this.http.post(getRequest.url, payload, getRequest.httpOptions);
public patchResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable<object> {
const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url);
- if (!isNullOrUndefined(apiURLHeader.httpOptions)) {
+ if (!this.isNullOrUndefined(apiURLHeader.httpOptions)) {
return this.http.patch(apiURLHeader.url, payload, apiURLHeader.httpOptions);
} else {
return this.http.patch(getRequest.url, payload, getRequest.httpOptions);
public putResource(apiURLHeader: { url: string, httpOptions?: { headers: HttpHeaders } }, payload: {}): Observable<object> {
const getRequest: APIURLHEADER = this.getHttpoptions(apiURLHeader.url);
- if (!isNullOrUndefined(apiURLHeader.httpOptions)) {
+ if (!this.isNullOrUndefined(apiURLHeader.httpOptions)) {
return this.http.put(apiURLHeader.url, payload, apiURLHeader.httpOptions);
} else {
return this.http.put(getRequest.url, payload, getRequest.httpOptions);
public deleteResource(apiURL: string, httpHeaders?: { headers: HttpHeaders }): Observable<object> {
const getRequest: APIURLHEADER = this.getHttpoptions(apiURL);
- if (!isNullOrUndefined(httpHeaders)) {
+ if (!this.isNullOrUndefined(httpHeaders)) {
return this.http.delete(apiURL, httpHeaders);
} else {
return this.http.delete(getRequest.url, getRequest.httpOptions);
}
}
+
/**
* Handle Error response based on the status.
* @param error The error response reecieved from API call.
* @param method The http request method.
*/
- // tslint:disable-next-line: cyclomatic-complexity
public handleError(err: ERRORDATA, method?: string): void {
if (err.error.status === HttpStatus.UNAUTHORIZED) {
if (method !== 'get') {
this.notifierService.notify('error', err.error.detail !== undefined ?
err.error.detail : this.translateService.instant('HTTPERROR.401'));
}
- this.activeModal.dismissAll();
+ } else {
+ this.notifierService.notify('error', err?.error?.detail !== undefined ?
+ err?.error?.detail : this.translateService.instant('HTTPERROR.401'));
}
+ this.activeModal.dismissAll();
} else if (err.error.status === HttpStatus.BAD_REQUEST) {
this.notifierService.notify('error', err.error.detail !== undefined ?
err.error.detail : this.translateService.instant('HTTPERROR.400'));
});
return {
url: apiURL,
- httpOptions: {headers : apiHeaders}
+ httpOptions: { headers: apiHeaders }
};
}
}