@@ -8,7 +8,7 @@ export default function (server) {
88 server . route ( {
99 path : '/api/analyze-api-ui-plugin/analyze' ,
1010 method : 'POST' ,
11- config : {
11+ options : {
1212 validate : {
1313 payload : Joi . object ( ) . keys ( {
1414 text : Joi . string ( ) . required ( ) ,
@@ -21,7 +21,7 @@ export default function (server) {
2121 } ) . required ( )
2222 }
2323 } ,
24- handler ( req , reply ) {
24+ handler : async ( req ) => {
2525
2626 // get params from req
2727 // call _analyze api
@@ -37,24 +37,22 @@ export default function (server) {
3737 if ( req . payload . charfilters ) param . body . char_filter = req . payload . charfilters ;
3838 if ( req . payload . field ) param . body . field = req . payload . field ;
3939 if ( req . payload . filters ) param . body . filter = req . payload . filters ;
40- call ( req , 'indices.analyze' , param )
41- . then ( function ( response ) {
42- let res = {
43- detail : response . detail ,
44- request : param . body
45- }
46- reply ( res ) ;
47- } )
48- . catch ( error => {
49- reply ( convertEsError ( param . index , error ) ) ;
50- } ) ;
40+ try {
41+ const response = await call ( req , 'indices.analyze' , param ) ;
42+ return {
43+ detail : response . detail ,
44+ request : param . body
45+ } ;
46+ } catch ( error ) {
47+ return convertEsError ( param . index , error ) ;
48+ }
5149 }
5250 } ) ;
5351
5452 server . route ( {
5553 path : '/api/analyze-api-ui-plugin/multi_analyze' ,
5654 method : 'POST' ,
57- config : {
55+ options : {
5856 validate : {
5957 payload : Joi . object ( ) . keys ( {
6058 text : Joi . string ( ) . required ( ) ,
@@ -66,7 +64,7 @@ export default function (server) {
6664 } ) . required ( )
6765 }
6866 } ,
69- handler ( req , reply ) {
67+ handler : async ( req , h ) => {
7068
7169 // get params from req
7270 // call _analyze api
@@ -106,13 +104,13 @@ export default function (server) {
106104 return 0 ;
107105 }
108106 ) ;
109- reply ( res ) ;
107+ return h . response ( res ) ;
110108 } )
111109 . catch ( error => {
112- reply ( convertEsError ( param . index , error ) ) ;
110+ return h . response ( convertEsError ( param . index , error ) ) ;
113111 } ) ;
114112 } else {
115- reply ( res ) ;
113+ return h . response ( res ) ;
116114 }
117115 }
118116 } ) ;
0 commit comments