Skip to content

Commit

Permalink
Adding unrecognized method in BaseExtensionRestHandler (#670)
Browse files Browse the repository at this point in the history
* Adding unrecognized method in BaseExtensionRestHandler

Signed-off-by: Varun Jain <[email protected]>

* Adding javadocs for unrecognized method in BaseExtensionRestHandler

Signed-off-by: Varun Jain <[email protected]>

* Addressing comments

Signed-off-by: Varun Jain <[email protected]>

* Adding unrecognized method in BaseRestExtensionHandler

Signed-off-by: Varun Jain <[email protected]>

* Adding unrecognized method in BaseRestExtensionHandler

Signed-off-by: Varun Jain <[email protected]>

---------

Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun authored Apr 12, 2023
1 parent e80ee7c commit e3dfb58
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/org/opensearch/sdk/BaseExtensionRestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

package org.opensearch.sdk;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.opensearch.rest.BaseRestHandler;
import static org.opensearch.rest.RestStatus.INTERNAL_SERVER_ERROR;
import static org.opensearch.rest.RestStatus.NOT_FOUND;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.extensions.rest.ExtensionRestResponse;
Expand Down Expand Up @@ -127,4 +129,22 @@ protected ExtensionRestResponse createJsonResponse(RestRequest request, RestStat
return new ExtensionRestResponse(request, status, fieldName + ": " + responseStr);
}
}

/**
* Returns a String message of the detail of any unrecognized error occurred. The string is intended for use in error messages to be returned to the user.
*
* @param request The request that caused the exception
* @param invalids Strings from the request which were unable to be understood.
* @param candidates A set of words that are most likely to be the valid strings determined invalid, to be suggested to the user.
* @param detail The parameter contains the details of the exception.
* @return a String that contains the message.
*/
protected final String unrecognized(
final RestRequest request,
final Set<String> invalids,
final Set<String> candidates,
final String detail
) {
return BaseRestHandler.unrecognizedStrings(request, invalids, candidates, detail);
}
}

0 comments on commit e3dfb58

Please sign in to comment.