File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed
plugin/src/main/java/org/opensearch/ml/rest Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -217,17 +217,22 @@ public MLTaskResponse read(StreamInput in) throws IOException {
217217 );
218218
219219 return Mono .fromCompletionStage (future );
220- } catch (IOException e ) {
221- return Mono .error (new OpenSearchStatusException ("Failed to parse request" , RestStatus .BAD_REQUEST , e ));
220+ } catch (Exception e ) {
221+ log .error ("Failed to parse or process request" , e );
222+ return Mono .error (e );
222223 }
223- }).doOnNext (channel ::sendChunk ).onErrorComplete (ex -> {
224- // Error handling
224+ }).doOnNext (channel ::sendChunk ).onErrorResume (ex -> {
225+ log . error ( " Error occurred" , ex );
225226 try {
226- channel .sendResponse (new BytesRestResponse (channel , (Exception ) ex ));
227- return true ;
228- } catch (final IOException e ) {
229- throw new UncheckedIOException (e );
227+ String errorMessage = ex instanceof IOException
228+ ? "Failed to parse request: " + ex .getMessage ()
229+ : "Error processing request: " + ex .getMessage ();
230+ HttpChunk errorChunk = createHttpChunk ("data: {\" error\" : \" " + errorMessage .replace ("\" " , "\\ \" " ) + "\" }\n \n " , true );
231+ channel .sendChunk (errorChunk );
232+ } catch (Exception e ) {
233+ log .error ("Failed to send error chunk" , e );
230234 }
235+ return Mono .empty ();
231236 }).subscribe ();
232237 };
233238
You can’t perform that action at this time.
0 commit comments