Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private request(url: string, method: RequestMethod, body?: any, isBlob = false): Observable {
const options = new BaseRequestOptions();
options.url = url;
options.method = method;
options.body = body;
if(isBlob) {
options.responseType = ResponseContentType.Blob;
}
const request = new Request(options);
return this.http.request(request)
.catch((error: any) => this.onErrorHandler(error));
}
private request(url : string, method : RequestMethod, body?: any, isBlob = false) : Observable < Response > {
this.showLoader();
const options = new BaseRequestOptions();
options.url = url;
options.method = method;
options.body = body;
if (isBlob) {
options.responseType = ResponseContentType.Blob;
}
const request = new Request(options);
return this
.http
.request(request)
.catch((error : any) => this.onErrorHandler(error))
. finally(() => {
this.onEnd();
});
}
request(options: IRequestOptions): Observable {
const req: Request = new Request(this.requestArgs(options));
return this.http.request(req)
.map((res: Response) => res.json());
}
private sendRequest(verb: RequestMethod,
url: string, body?: Product | Order, auth: boolean = false)
: Observable {
let request = new Request({
method: verb,
url: this.baseUrl + url,
body: body
});
if (auth && this.auth_token != null) {
request.headers.set("Authorization", `Bearer<${this.auth_token}>`);
}
return this.http.request(request).map(response => response.json());
}
}
request(request: RequestOptions): Observable {
request.method = (request.method || RequestMethod.Get);
request.url = (request.url || '');
request.headers = (request.headers || {});
request.data = (request.data || {});
request.params = (request.params || {});
request.apiName = (request.apiName || this._defaultApiName);
this._interpolateUrl(request);
this._addContentType(request);
this._addAuthToken(request);
return this.http.request(
new Request({
method: request.method,
url: this._buildApiUrl(request),
headers: request.headers,
search: this._buildUrlSearchParams(request.params),
body: JSON.stringify(request.data, dateReplacer)
} as RequestArgs)
).catch(error => this._handleError(error))
.map((res: Response) => this._unwrapAndCastHttpResponse(res));
}
public options(conn: ApiConnection, path: string): Observable {
if (path.indexOf("/") != 0) {
path = '/' + path;
}
let opts: RequestOptionsArgs = {
method: RequestMethod.Options,
url: conn.url + path,
headers: new Headers(),
search: undefined,
body: undefined
};
return this._http.request(new Request(new RequestOptions(opts)));
}
public fetch(options: RequestOptions): Observable {
return this.http.request(new Request(options)).pipe(
map(this.getJsonData),
);
}
return Observable.create((observer: Observer) => {
this.process.next(Action.QueryStart);
this._http.request(new Request(requestOptions))
.map((res) => res.json())
.finally(() => {
this.process.next(Action.QueryStop);
})
.subscribe((res) => {
if (reqOptions.handle !== false) {
observer.next(this.serverHandler.handleSuccess(res));
} else {
observer.next(res);
}
observer.complete();
},
(err) => {
if (reqOptions.handle !== false) {
observer.error(this.serverHandler.handleError(err));
} else {
request(url: string, method: RequestMethod, body?: Object): Observable {
const headers = new Headers();
headers.append('Content-type', 'application/json');
headers.append('Authorization', `Bearer ${this.authService.getToken()}`);
const requestOptions = new RequestOptions({
url: `${this.baseUrl}/${url}`,
headers: headers,
method: method
});
if (body) {
requestOptions.body = body;
}
const req = new Request(requestOptions);
return this.http.request(req)
.map((res: Response) => res.json())
.catch((error: Response) => this.onRequestError(error));
}