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

feat(error-handling): return status 504 instead of 500 for triplestore timeout exception (DEV-749) #2046

Merged
Merged
2 changes: 2 additions & 0 deletions docs/03-apis/api-v2/query-language.md
Expand Up @@ -73,6 +73,8 @@ HTTP POST to http://host/v2/searchextended/count
The response to a count query request is an object with one predicate,
`http://schema.org/numberOfItems`, with an integer value.

If a gravsearch query times out, a `504 Gateway Timeout` will be returned.

## Gravsearch and API Schemas

A Gravsearch query can be written in either of the two
Expand Down
Expand Up @@ -31,9 +31,10 @@ object ApiStatusCodesV2 {
case RequestRejectedException(_) => StatusCodes.BadRequest

// Subclasses of InternalServerException (which must be last in this group)
case UpdateNotPerformedException(_) => StatusCodes.Conflict
case InternalServerException(_) => StatusCodes.InternalServerError
case _ => StatusCodes.InternalServerError
case UpdateNotPerformedException(_) => StatusCodes.Conflict
case TriplestoreTimeoutException(_, _) => StatusCodes.GatewayTimeout
case InternalServerException(_) => StatusCodes.InternalServerError
case _ => StatusCodes.InternalServerError
}

}
Expand Up @@ -965,10 +965,11 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat
Option(response.getEntity)
.map(responseEntity => EntityUtils.toString(responseEntity, StandardCharsets.UTF_8)) match {
case Some(responseEntityStr) =>
log.error(s"Triplestore responded with HTTP code $statusCode: $responseEntityStr")
throw TriplestoreResponseException(
s"Triplestore responded with HTTP code $statusCode: $responseEntityStr"
)
val msg = s"Triplestore responded with HTTP code $statusCode: $responseEntityStr"
log.error(msg)
if (statusCode == 503 && responseEntityStr.contains("Query timed out"))
throw TriplestoreTimeoutException(msg)
else throw TriplestoreResponseException(msg)

case None =>
log.error(s"Triplestore responded with HTTP code $statusCode")
Expand All @@ -995,6 +996,10 @@ class HttpTriplestoreConnector extends Actor with ActorLogging with Instrumentat
log.error(socketTimeoutException, message)
throw TriplestoreTimeoutException(message = message, e = socketTimeoutException, log = log)

case timeout: TriplestoreTimeoutException =>
log.warning("Can not recover from Triplestore Timeout")
throw timeout

case notFound: NotFoundException => throw notFound

case e: Exception =>
Expand Down