Skip to content

Commit

Permalink
Remove exception class InvalidPayloadException and re-throw CannotTra…
Browse files Browse the repository at this point in the history
…nsformContentToTypeException instead
  • Loading branch information
timemanx committed Dec 30, 2024
1 parent f454845 commit d2a7347
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fun StatusPagesConfig.defaultGraphQLStatusPages(): StatusPagesConfig {
exception<Throwable> { call, cause ->
when (cause) {
is UnsupportedOperationException -> call.respond(HttpStatusCode.MethodNotAllowed)
is InvalidPayloadException -> call.respond(HttpStatusCode.UnsupportedMediaType)
else -> call.respond(HttpStatusCode.BadRequest)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d2a7347

Please sign in to comment.