20
20
import org .opensearch .action .search .SearchResponse ;
21
21
import org .opensearch .client .Client ;
22
22
import org .opensearch .common .unit .TimeValue ;
23
+ import org .opensearch .core .rest .RestStatus ;
23
24
import org .opensearch .rest .BytesRestResponse ;
24
25
import org .opensearch .rest .RestChannel ;
25
26
import org .opensearch .search .SearchHit ;
36
37
import org .opensearch .sql .legacy .pit .PointInTimeHandler ;
37
38
import org .opensearch .sql .legacy .pit .PointInTimeHandlerImpl ;
38
39
import org .opensearch .sql .legacy .rewriter .matchtoterm .VerificationException ;
40
+ import org .opensearch .sql .opensearch .response .error .ErrorMessageFactory ;
39
41
40
42
public class CursorResultExecutor implements CursorRestExecutor {
41
43
@@ -58,7 +60,15 @@ public void execute(Client client, Map<String, String> params, RestChannel chann
58
60
} catch (IllegalArgumentException | JSONException e ) {
59
61
Metrics .getInstance ().getNumericalMetric (MetricName .FAILED_REQ_COUNT_CUS ).increment ();
60
62
LOG .error ("Error parsing the cursor" , e );
61
- channel .sendResponse (new BytesRestResponse (channel , e ));
63
+ channel .sendResponse (
64
+ new BytesRestResponse (
65
+ RestStatus .BAD_REQUEST ,
66
+ "application/json; charset=UTF-8" ,
67
+ ErrorMessageFactory .createErrorMessage (
68
+ new IllegalArgumentException (
69
+ "Malformed cursor: unable to extract cursor information" ),
70
+ RestStatus .BAD_REQUEST .getStatus ())
71
+ .toString ()));
62
72
} catch (OpenSearchException e ) {
63
73
int status = (e .status ().getStatus ());
64
74
if (status > 399 && status < 500 ) {
0 commit comments