Skip to content

Commit

Permalink
Status code changes for /loadsearch endpoint (#1)
Browse files Browse the repository at this point in the history
* server returns 204 on no result found, 500 on no search source registered

* minor fix and update doc
  • Loading branch information
bachtran02 authored Oct 12, 2023
1 parent 9d88452 commit 12561f7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ The endpoint returns a [search result](#search-result-object) JSON object

</details>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public void shutdown() {
}

@Nullable
public AudioSearchResult loadSearch(String query, Set<AudioSearchResult.Type> types) {
public AudioSearchResult loadSearch(String query, Set<AudioSearchResult.Type> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 12561f7

Please sign in to comment.