Skip to content

Commit

Permalink
fix: use 400 instead of 500 for invalid input in fulltext search (DEV…
Browse files Browse the repository at this point in the history
  • Loading branch information
irinaschubert committed Apr 6, 2023
1 parent f94bb82 commit 51acceb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Expand Up @@ -21,6 +21,7 @@ import org.knora.webapi.messages.v2.responder.valuemessages.ReadValueV2
import org.knora.webapi.messages.v2.responder.valuemessages.StillImageFileValueContentV2
import org.knora.webapi.responders.v2.ResourcesResponseCheckerV2.compareReadResourcesSequenceV2Response
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import dsp.errors.BadRequestException

/**
* Tests [[SearchResponderV2]].
Expand Down Expand Up @@ -80,6 +81,26 @@ class SearchResponderV2Spec extends CoreSpec with ImplicitSender {

}

"return a Bad Request error if fulltext search input is invalid" in {

appActor ! FulltextSearchRequestV2(
searchValue = "qin(",
offset = 0,
limitToProject = None,
limitToResourceClass = None,
limitToStandoffClass = None,
returnFiles = false,
targetSchema = ApiV2Complex,
schemaOptions = SchemaOptions.ForStandoffWithTextValues,
requestingUser = SharedTestDataADM.anythingUser1
)

expectMsgPF(timeout) { case msg: akka.actor.Status.Failure =>
assert(msg.cause.isInstanceOf[BadRequestException])
}

}

"return files attached to full-text search results" in {

appActor ! FulltextSearchRequestV2(
Expand Down
Expand Up @@ -164,7 +164,6 @@ case class TriplestoreServiceLive(
for {
resultStr <-
getSparqlHttpResponse(sparql, isUpdate = false, simulateTimeout = simulateTimeout, isGravsearch = isGravsearch)

// Parse the response as a JSON object and generate a response message.
responseMessage <- parseJsonResponse(sparql, resultStr)
} yield responseMessage
Expand Down Expand Up @@ -681,9 +680,7 @@ case class TriplestoreServiceLive(
acceptMimeType: String = mimeTypeApplicationSparqlResultsJson,
simulateTimeout: Boolean = false
): Task[String] = {

val httpClient = ZIO.attempt(queryHttpClient)

val httpPost = ZIO.attempt {
if (isUpdate) {
// Send updates as application/sparql-update (as per SPARQL 1.1 Protocol §3.2.2, "UPDATE using POST directly").
Expand Down Expand Up @@ -882,6 +879,8 @@ case class TriplestoreServiceLive(

(statusCode, entity) match {
case (404, _) => ZIO.fail(NotFoundException.notFound)
case (500, Some(response)) if response.contains("Text search parse error") =>
ZIO.fail(BadRequestException(s"$response"))
case (500, _) => ZIO.fail(TriplestoreResponseException(statusResponseMsg))
case (503, Some(response)) if response.contains("Query timed out") =>
ZIO.fail(TriplestoreTimeoutException(s"$statusResponseMsg: $response"))
Expand Down

0 comments on commit 51acceb

Please sign in to comment.