Skip to content

Commit 8ca2b1f

Browse files
committed
minor fix
1 parent 4a1d59c commit 8ca2b1f

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

api/autocomplete/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
66
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs/autocomplete?api-version=2019-05-06&`;
77
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/autocomplete(\?)?/i, searchApiUrl);
88

9-
const searchApiResponse = await axios.get(url, {
10-
headers: {
11-
"api-key": process.env.SearchApiKey,
12-
} });
9+
try {
10+
11+
const response = await axios.get(url, {
12+
headers: {
13+
"api-key": process.env.SearchApiKey,
14+
} });
15+
16+
context.res = {
17+
status: response.status,
18+
body: response.data,
19+
};
1320

14-
context.res = {
15-
status: searchApiResponse.status,
16-
body: searchApiResponse.data,
17-
};
21+
} catch (err) {
22+
context.res = {
23+
status: err.response?.status ?? 500
24+
};
25+
}
1826
};
1927

2028
export default httpTrigger;

api/lookup/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
66
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs`;
77
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/lookup/i, searchApiUrl);
88

9-
const searchApiResponse = await axios.get(`${url}?api-version=2019-05-06`, {
10-
headers: {
11-
"api-key": process.env.SearchApiKey,
12-
} });
13-
14-
context.res = {
15-
status: searchApiResponse.status,
16-
body: searchApiResponse.data,
17-
};
9+
try {
10+
11+
const response = await axios.get(`${url}?api-version=2019-05-06`, {
12+
headers: {
13+
"api-key": process.env.SearchApiKey,
14+
} });
15+
16+
context.res = {
17+
status: response.status,
18+
body: response.data,
19+
};
20+
21+
} catch (err) {
22+
context.res = {
23+
status: err.response?.status ?? 500
24+
};
25+
}
1826
};
1927

2028
export default httpTrigger;

api/search/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
66
const searchApiUrl = `https://${process.env.SearchServiceName}.search.windows.net/indexes/${process.env.SearchIndexName}/docs?api-version=2019-05-06&`;
77
const url = req.url.replace(/^http(s)?:\/\/[^/]+\/api\/search(\?)?/i, searchApiUrl);
88

9-
const searchApiResponse = await axios.get(url, {
10-
headers: {
11-
"api-key": process.env.SearchApiKey,
12-
} });
13-
14-
context.res = {
15-
status: searchApiResponse.status,
16-
body: searchApiResponse.data,
17-
};
9+
try {
10+
11+
const response = await axios.get(url, {
12+
headers: {
13+
"api-key": process.env.SearchApiKey,
14+
} });
15+
16+
context.res = {
17+
status: response.status,
18+
body: response.data,
19+
};
20+
21+
} catch (err) {
22+
context.res = {
23+
status: err.response?.status ?? 500
24+
};
25+
}
1826
};
1927

2028
export default httpTrigger;

0 commit comments

Comments
 (0)