Skip to content

Commit

Permalink
Fix MultiGetHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
adamseres committed Jan 6, 2025
1 parent f44355e commit 4d701c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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"
}
}

0 comments on commit 4d701c3

Please sign in to comment.