Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MultiGetResponse error handling #3276

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ trait GetHandlers {

implicit object MultiGetHandler extends Handler[MultiGetRequest, MultiGetResponse] {

override def responseHandler: ResponseHandler[MultiGetResponse] = new ResponseHandler[MultiGetResponse] {
override def handle(response: HttpResponse): Either[ElasticError, MultiGetResponse] = response.statusCode match {
case 404 | 500 => sys.error(response.toString)
case _ => Right(ResponseHandler.fromResponse[MultiGetResponse](response))
}
}

override def build(request: MultiGetRequest): ElasticRequest = {
val body = MultiGetBodyBuilder(request).string
val entity = HttpEntity(body, "application/json")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sksamuel.elastic4s.requests.get

import com.sksamuel.elastic4s.{Authentication, CommonRequestOptions}
import com.sksamuel.elastic4s.requests.common.RefreshPolicy
import com.sksamuel.elastic4s.testkit.DockerTests
import org.scalatest.flatspec.AnyFlatSpec
Expand Down Expand Up @@ -107,4 +108,14 @@ class MultiGetTest extends AnyFlatSpec with MockitoSugar with DockerTests {
resp.items.head.id shouldBe "3"
resp.items.head.exists shouldBe true
}

it should "error if authentication is unsuccessful" in {
implicit val requestOptions: CommonRequestOptions = CommonRequestOptions.defaults.copy(
authentication = Authentication.UsernamePassword("not_exists", "pass123")
)

client.execute(
multiget(get("coldplay", "3") routing "3")
).await.error.`type` shouldBe "security_exception"
}
}
Loading