Add check for query length.

This commit is contained in:
Kavin 2023-03-04 03:03:06 +00:00
parent 20bff208d2
commit cb598371b0
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -28,6 +28,9 @@ public class SearchHandlers {
if (StringUtils.isEmpty(query))
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query is a required parameter"));
if (query.length() > 100)
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query is too long"));
return mapper.writeValueAsBytes(YOUTUBE_SERVICE.getSuggestionExtractor().suggestionList(query));
}
@ -38,6 +41,9 @@ public class SearchHandlers {
if (StringUtils.isEmpty(query))
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query is a required parameter"));
if (query.length() > 100)
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query is too long"));
return mapper.writeValueAsBytes(Arrays.asList(
query,
YOUTUBE_SERVICE.getSuggestionExtractor().suggestionList(query)