Skip to content

Commit 43d3bcb

Browse files
Re-use helper.
Signed-off-by: Finn Carroll <carrofin@amazon.com>
1 parent efa65e1 commit 43d3bcb

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private void handleException(RestChannel restChannel, Exception exception) {
210210
reportError(restChannel, exception, status);
211211
}
212212

213-
private static RestStatus getRestStatus(Exception ex) {
213+
public static RestStatus getRestStatus(Exception ex) {
214214
int code = getRawErrorCode(ex);
215215
return RestStatus.fromCode(code);
216216
}

plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,8 @@ protected Object buildJsonObject(ExplainResponse resp) {
263263

264264
@Override
265265
public void onFailure(Exception e) {
266-
RestStatus status =
267-
(e instanceof org.opensearch.OpenSearchException osEx)
268-
? osEx.status()
269-
: RestStatus.INTERNAL_SERVER_ERROR;
270-
channel.sendResponse(new BytesRestResponse(status, e.getMessage()));
266+
channel.sendResponse(
267+
new BytesRestResponse(RestSqlAction.getRestStatus(e), e.getMessage()));
271268
}
272269
});
273270
} else {
@@ -285,11 +282,8 @@ public void onResponse(TransportPPLQueryResponse response) {
285282

286283
@Override
287284
public void onFailure(Exception e) {
288-
RestStatus status =
289-
(e instanceof org.opensearch.OpenSearchException osEx)
290-
? osEx.status()
291-
: RestStatus.INTERNAL_SERVER_ERROR;
292-
channel.sendResponse(new BytesRestResponse(status, e.getMessage()));
285+
channel.sendResponse(
286+
new BytesRestResponse(RestSqlAction.getRestStatus(e), e.getMessage()));
293287
}
294288
});
295289
}

0 commit comments

Comments
 (0)