From 12561f7fa08f41da10a2ade92d0258b3159a9f9b Mon Sep 17 00:00:00 2001 From: Peter Tran <83796054+bachtran02@users.noreply.github.com> Date: Thu, 12 Oct 2023 02:52:02 -0700 Subject: [PATCH] Status code changes for /loadsearch endpoint (#1) * server returns 204 on no result found, 500 on no search source registered * minor fix and update doc --- README.md | 2 +- .../java/com/github/topi314/lavasearch/SearchManager.java | 5 ++++- .../topi314/lavasearch/plugin/AudioSearchRestHandler.kt | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2bba81c..ce6c956 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ The endpoint returns a [search result](#search-result-object) JSON object -If no results are found the endpoint returns a http status code of `404` +If no results are found the endpoint returns a http status code of `204 No Content` ### Text Object diff --git a/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java b/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java index b28b50b..abaf0d1 100644 --- a/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java +++ b/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java @@ -41,7 +41,10 @@ public void shutdown() { } @Nullable - public AudioSearchResult loadSearch(String query, Set types) { + public AudioSearchResult loadSearch(String query, Set types) throws IllegalStateException { + if (this.searchManagers.isEmpty()){ + throw new IllegalStateException("No search source registered"); + } for (var sourceManager : this.searchManagers) { var searchResults = sourceManager.loadSearch(query, types); if (searchResults != null) { diff --git a/plugin/src/main/java/com/github/topi314/lavasearch/plugin/AudioSearchRestHandler.kt b/plugin/src/main/java/com/github/topi314/lavasearch/plugin/AudioSearchRestHandler.kt index 5b4f960..7e8ad88 100644 --- a/plugin/src/main/java/com/github/topi314/lavasearch/plugin/AudioSearchRestHandler.kt +++ b/plugin/src/main/java/com/github/topi314/lavasearch/plugin/AudioSearchRestHandler.kt @@ -36,6 +36,6 @@ class AudioSearchRestHandler( val result = searchManager.loadSearch(query, finalTypes) return if (result != null) { ResponseEntity.ok(result.toSearchResult(playerManager, pluginInfoModifiers, searchResultInfoModifiers)) - } else ResponseEntity.notFound().build() + } else ResponseEntity.noContent().build() } }