From f7904b219ec6180299a156b7ceb0cab8a6b7bede Mon Sep 17 00:00:00 2001 From: Peter Tran Date: Sun, 8 Oct 2023 14:51:32 -0700 Subject: [PATCH 1/2] server returns 204 on no result found, 500 on no search source registered --- .../java/com/github/topi314/lavasearch/SearchManager.java | 5 ++++- .../topi314/lavasearch/plugin/AudioSearchRestHandler.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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..d837c4a 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() } } From 6f9bbb09d1abb1f786fc62c6dc19419339cf9273 Mon Sep 17 00:00:00 2001 From: Peter Tran Date: Sun, 8 Oct 2023 16:52:35 -0700 Subject: [PATCH 2/2] minor fix and update doc --- README.md | 2 +- .../main/java/com/github/topi314/lavasearch/SearchManager.java | 2 +- 2 files changed, 2 insertions(+), 2 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 d837c4a..abaf0d1 100644 --- a/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java +++ b/main/src/main/java/com/github/topi314/lavasearch/SearchManager.java @@ -43,7 +43,7 @@ public void shutdown() { @Nullable public AudioSearchResult loadSearch(String query, Set types) throws IllegalStateException { if (this.searchManagers.isEmpty()){ - throw new IllegalStateException("No search source registered!"); + throw new IllegalStateException("No search source registered"); } for (var sourceManager : this.searchManagers) { var searchResults = sourceManager.loadSearch(query, types);