Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Aug 25, 2023
1 parent 01e8bb7 commit 094b66c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions http/http/src/main/kotlin/com/hexagonkt/http/Http.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.hexagonkt.http

import com.hexagonkt.core.assertEnabled
import com.hexagonkt.core.Jvm
import com.hexagonkt.core.logging.Logger
import com.hexagonkt.core.media.MediaType
import com.hexagonkt.http.model.*
import java.lang.IllegalStateException
import java.math.BigInteger
import java.net.URLDecoder
import java.net.URLEncoder
Expand All @@ -22,6 +24,8 @@ val BODY_TYPES = setOf(String::class, ByteArray::class, Int::class, Long::class)

val BODY_TYPES_NAMES = BODY_TYPES.joinToString(", ") { it.simpleName.toString() }

private val logger: Logger = Logger(SslSettings::class.java.packageName)

fun checkHeaders(headers: Headers) {
if (!assertEnabled)
return
Expand Down Expand Up @@ -124,6 +128,12 @@ fun bodyToBytes(body: Any): ByteArray =
is ByteArray -> body
is Int -> BigInteger.valueOf(body.toLong()).toByteArray()
is Long -> BigInteger.valueOf(body).toByteArray()
else ->
error("Unsupported body type: ${body.javaClass.simpleName}. Must be: $BODY_TYPES_NAMES")
else -> {
val className = body.javaClass.simpleName
val message = "Unsupported body type: $className. Must be: $BODY_TYPES_NAMES"
val exception = IllegalStateException(message)

logger.error(exception)
throw exception
}
}

0 comments on commit 094b66c

Please sign in to comment.