Remove ServiceClient.pipeline() in favor of ServiceClient.sendRequest()

This commit is contained in:
Dan Schulte 2018-05-07 14:20:10 -07:00
Родитель 32ecf587e6
Коммит a839efebec
2 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -108,16 +108,6 @@ export class ServiceClient {
this._requestPolicyCreators = options.requestPolicyCreators || createDefaultRequestPolicyCreators(credentials, options, this.userAgentInfo.value);
}
pipeline(request: WebResource): Promise<HttpOperationResponse> {
let httpPipeline: RequestPolicy = this._httpClient;
if (this._requestPolicyCreators && this._requestPolicyCreators.length > 0) {
for (let i = this._requestPolicyCreators.length - 1; i >= 0; --i) {
httpPipeline = this._requestPolicyCreators[i](httpPipeline, this._requestPolicyOptions);
}
}
return httpPipeline.sendRequest(request);
}
/**
* Adds custom information to user agent header
* @param {any} additionalUserAgentInfo - information to be added to user agent header, as string.
@ -149,7 +139,13 @@ export class ServiceClient {
// send request
let operationResponse: HttpOperationResponse;
try {
operationResponse = await this.pipeline(httpRequest);
let httpPipeline: RequestPolicy = this._httpClient;
if (this._requestPolicyCreators && this._requestPolicyCreators.length > 0) {
for (let i = this._requestPolicyCreators.length - 1; i >= 0; --i) {
httpPipeline = this._requestPolicyCreators[i](httpPipeline, this._requestPolicyOptions);
}
}
operationResponse = await httpPipeline.sendRequest(httpRequest);
} catch (err) {
return Promise.reject(err);
}

Просмотреть файл

@ -39,11 +39,18 @@ export class WebResource {
* mentioned properties are not defined.
*/
validateRequestProperties(): void {
if (!this.method || !this.url || !this.headers["Content-Type"] || !this.headers["accept-language"]) {
throw new Error("method, url, headers[\"Content-Type\"], headers[\"accept-language\"] are " +
"required properties before making a request. Either provide them or use WebResource.prepare() method.");
if (!this.method) {
throw new Error("method is a required property for making a request.");
}
return;
if (!this.url) {
throw new Error("url is a required property for making a request.");
}
if (!this.headers["Content-Type"]) {
throw new Error("'Content-Type' is a required header for making a request.");
}
// if (!this.headers["accept-language"]) {
// throw new Error("'accept-language' is a required header for making a request.");
// }
}
/**