From d2a73476c36148c7b62d5e81929349cdb54afb7d Mon Sep 17 00:00:00 2001 From: timemanx Date: Mon, 30 Dec 2024 15:39:57 +0900 Subject: [PATCH] Remove exception class InvalidPayloadException and re-throw CannotTransformContentToTypeException instead --- .../expediagroup/graphql/server/ktor/GraphQLStatusPages.kt | 1 - .../graphql/server/ktor/KtorGraphQLRequestParser.kt | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLStatusPages.kt b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLStatusPages.kt index 2363eb09d7..74ce52b2cb 100644 --- a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLStatusPages.kt +++ b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/GraphQLStatusPages.kt @@ -31,7 +31,6 @@ fun StatusPagesConfig.defaultGraphQLStatusPages(): StatusPagesConfig { exception { call, cause -> when (cause) { is UnsupportedOperationException -> call.respond(HttpStatusCode.MethodNotAllowed) - is InvalidPayloadException -> call.respond(HttpStatusCode.UnsupportedMediaType) else -> call.respond(HttpStatusCode.BadRequest) } } diff --git a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParser.kt b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParser.kt index 8b66b98d93..de8601c434 100644 --- a/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParser.kt +++ b/servers/graphql-kotlin-ktor-server/src/main/kotlin/com/expediagroup/graphql/server/ktor/KtorGraphQLRequestParser.kt @@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.type.MapType import com.fasterxml.jackson.databind.type.TypeFactory import io.ktor.http.HttpMethod +import io.ktor.server.plugins.CannotTransformContentToTypeException import io.ktor.server.request.ApplicationRequest import io.ktor.server.request.receive import java.io.IOException @@ -31,8 +32,6 @@ internal const val REQUEST_PARAM_QUERY = "query" internal const val REQUEST_PARAM_OPERATION_NAME = "operationName" internal const val REQUEST_PARAM_VARIABLES = "variables" -class InvalidPayloadException(message: String, throwable: Throwable) : IllegalStateException(message, throwable) - /** * GraphQL Ktor [ApplicationRequest] parser. */ @@ -63,7 +62,9 @@ open class KtorGraphQLRequestParser( private suspend fun parsePostRequest(request: ApplicationRequest): GraphQLServerRequest? = try { request.call.receive() + } catch (e: CannotTransformContentToTypeException) { + throw e } catch (e: IOException) { - throw InvalidPayloadException("Invalid HTTP request - unable to parse GraphQL request from POST payload", e) + throw IllegalStateException("Invalid HTTP request - unable to parse GraphQL request from POST payload", e) } }