File tree Expand file tree Collapse file tree 3 files changed +50
-26
lines changed Expand file tree Collapse file tree 3 files changed +50
-26
lines changed Original file line number Diff line number Diff 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 ( / ^ h t t p ( s ) ? : \/ \/ [ ^ / ] + \/ a p i \/ a u t o c o m p l e t e ( \? ) ? / 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
2028export default httpTrigger ;
Original file line number Diff line number Diff 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 ( / ^ h t t p ( s ) ? : \/ \/ [ ^ / ] + \/ a p i \/ l o o k u p / 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
2028export default httpTrigger ;
Original file line number Diff line number Diff 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 ( / ^ h t t p ( s ) ? : \/ \/ [ ^ / ] + \/ a p i \/ s e a r c h ( \? ) ? / 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
2028export default httpTrigger ;
You can’t perform that action at this time.
0 commit comments