File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
datasources/src/main/java/org/opensearch/sql/datasources Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change 77package org .opensearch .sql .datasources .exceptions ;
88
99import com .google .gson .Gson ;
10+ import com .google .gson .GsonBuilder ;
1011import com .google .gson .JsonObject ;
1112import lombok .Getter ;
1213import org .opensearch .rest .RestStatus ;
@@ -65,7 +66,8 @@ public String toString() {
6566 JsonObject jsonObject = new JsonObject ();
6667 jsonObject .addProperty ("status" , status );
6768 jsonObject .add ("error" , getErrorAsJson ());
68- return new Gson ().toJson (jsonObject );
69+ Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
70+ return gson .toJson (jsonObject );
6971 }
7072
7173 private JsonObject getErrorAsJson () {
Original file line number Diff line number Diff line change 2121import java .util .Locale ;
2222import org .apache .logging .log4j .LogManager ;
2323import org .apache .logging .log4j .Logger ;
24+ import org .opensearch .OpenSearchException ;
2425import org .opensearch .action .ActionListener ;
2526import org .opensearch .client .node .NodeClient ;
2627import org .opensearch .rest .BaseRestHandler ;
@@ -224,6 +225,9 @@ public void onFailure(Exception e) {
224225 private void handleException (Exception e , RestChannel restChannel ) {
225226 if (e instanceof DataSourceNotFoundException ) {
226227 reportError (restChannel , e , NOT_FOUND );
228+ } else if (e instanceof OpenSearchException ) {
229+ OpenSearchException exception = (OpenSearchException ) e ;
230+ reportError (restChannel , exception , exception .status ());
227231 } else {
228232 LOG .error ("Error happened during request handling" , e );
229233 if (isClientError (e )) {
You can’t perform that action at this time.
0 commit comments