Skip to content

Commit 7449306

Browse files
committed
Linting pass
1 parent 2ab2421 commit 7449306

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

quickstart/AzureSearchClient.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AzureSearchClient {
1414

1515
getSearchUrl(searchTerm) { return `https://${this.searchServiceName}.search.windows.net/indexes/${this.indexName}/docs?api-version=${this.apiVersion}&search=${searchTerm}&searchMode=all`; }
1616

17-
request(url, method, bodyJson = null) {
17+
static request(url, method, apiKey, bodyJson = null) {
1818
// Uncomment the following for request details:
1919
/*
2020
console.log(`\n${method} ${url}`);
@@ -25,35 +25,35 @@ class AzureSearchClient {
2525

2626
const headers = {
2727
'content-type' : 'application/json',
28-
'api-key' : this.apiKey
28+
'api-key' : apiKey
2929
};
3030
const init = bodyJson === null ?
3131
{
32-
method : method,
33-
headers : headers
32+
method,
33+
headers
3434
}
3535
:
3636
{
37-
method : method,
38-
headers : headers,
37+
method,
38+
headers,
3939
body : JSON.stringify(bodyJson)
4040
};
4141
return fetch(url, init);
4242
}
4343

44-
throwOnHttpError(response) {
44+
static throwOnHttpError(response) {
4545
const statusCode = response.status;
4646
console.log(`Response Status: ${statusCode}`);
4747
if (statusCode >= 300){
4848
console.log(`Request failed: ${JSON.stringify(response, null, 4)}`);
49-
throw new Exception(`Failure in request. HTTP Status was ${statusCode}`);
49+
throw new Error(`Failure in request. HTTP Status was ${statusCode}`);
5050
}
5151
}
5252

5353
async indexExistsAsync() {
5454
console.log("\n Checking if index exists...");
5555
const endpoint = this.getIndexUrl();
56-
const response = await this.request(endpoint, "GET", null);
56+
const response = await this.request(endpoint, "GET", this.apiKey);
5757
// Success has a few likely status codes: 200 or 204 (No Content), but accept all in 200 range...
5858
const exists = response.status >= 200 && response.status < 300;
5959
return exists;
@@ -62,31 +62,31 @@ class AzureSearchClient {
6262
async deleteIndexAsync() {
6363
console.log("\n Deleting existing index...");
6464
const endpoint = this.getIndexUrl();
65-
const response = await this.request(endpoint, "DELETE");
65+
const response = await this.request(endpoint, "DELETE", this.apiKey);
6666
this.throwOnHttpError(response);
6767
return this;
6868
}
6969

7070
async createIndexAsync(definition) {
7171
console.log("\n Creating index...");
7272
const endpoint = this.getIndexUrl();
73-
const response = await this.request(endpoint, "PUT", definition);
73+
const response = await this.request(endpoint, "PUT", this.apiKey, definition);
7474
this.throwOnHttpError(response);
7575
return this;
7676
}
7777

7878
async postDataAsync(hotelsData) {
7979
console.log("\n Adding hotel data...");
8080
const endpoint = this.getPostDataUrl();
81-
const response = await this.request(endpoint,"POST", hotelsData);
81+
const response = await this.request(endpoint,"POST", this.apiKey, hotelsData);
8282
this.throwOnHttpError(response);
8383
return this;
8484
}
8585

8686
async queryAsync(searchTerm) {
8787
console.log("\n Querying...")
8888
const endpoint = this.getSearchUrl(searchTerm);
89-
const response = await this.request(endpoint, "GET");
89+
const response = await this.request(endpoint, "GET", this.apiKey);
9090
this.throwOnHttpError(response);
9191
return response;
9292
}

quickstart/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const AzureSearchClient = require('./AzureSearchClient.js');
66
function getAzureConfiguration() {
77
const config = nconf.file({ file: 'azure_search_config.json' });
88
if (config.get('serviceName') == '[SEARCH_SERVICE_NAME' || config.get('apiKey') == '[SEARCH_SERVICE_API_KEY]') {
9-
throw "You have not set the values in your azure_search_config.json file. Please change them to match your search service's values."
9+
throw new Error("You have not set the values in your azure_search_config.json file. Please change them to match your search service's values.");
1010
}
1111
return config;
1212
}

0 commit comments

Comments
 (0)