Skip to content

Commit

Permalink
Use logger instead of printing stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
colinchilds committed Aug 9, 2021
1 parent 810bd8c commit 6d8bebb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ dependencies {
implementation("io.vertx:vertx-pg-client:$vertxVersion")
implementation("io.vertx:vertx-config:$vertxVersion")
implementation("org.postgresql:postgresql:42.2.22")
implementation("com.google.guava:guava:28.1-jre")

implementation("org.reflections:reflections:0.9.11")
implementation("org.slf4j:slf4j-jdk14:1.7.32")

implementation("org.apache.commons:commons-collections4:4.0")
}
Expand Down
17 changes: 8 additions & 9 deletions src/main/kotlin/me/koddle/tools/OpenAPIRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ import me.koddle.exceptions.ResponseCodeException
import me.koddle.exceptions.TimeoutException
import me.koddle.json.jArr
import me.koddle.security.AuthManager
import org.slf4j.LoggerFactory
import java.lang.reflect.InvocationTargetException
import kotlin.reflect.KAnnotatedElement
import kotlin.reflect.KCallable
import kotlin.reflect.KClass
import kotlin.reflect.KParameter
import kotlin.reflect.KType
import kotlin.reflect.*
import kotlin.reflect.full.callSuspendBy
import kotlin.reflect.full.instanceParameter
import kotlin.reflect.full.isSubclassOf
Expand All @@ -35,6 +32,8 @@ class OpenAPIRouterOptions(val bodyHandler: BodyHandler? = BodyHandler.create().
val authManager: AuthManager? = null,
val defaultRequestTimeout: Long = 30_000)

private val LOGGER = LoggerFactory.getLogger(OpenAPIRouter::class.java)

fun Router.route(openApiFile: OpenAPI, controllerLookup: (controllerName: String) -> Any?, options: OpenAPIRouterOptions) {
route()
.produces("application/json")
Expand Down Expand Up @@ -95,7 +94,7 @@ object OpenAPIRouter {
.failureHandler { replyWithError(it, it.failure()) }
}
} catch (ex: Exception) {
ex.printStackTrace()
LOGGER.info("Unable to load router", ex)
exitProcess(1)
}
}
Expand Down Expand Up @@ -138,18 +137,18 @@ object OpenAPIRouter {
}
failure is ResponseCodeException -> {
if (failure.statusCode.value() >= 500) {
failure.printStackTrace()
LOGGER.error("Server Error", failure)
}
response.putHeader("content-type", "application/json")
.setStatusCode(failure.statusCode.value())
.end(failure.asJson().encode())
}
context.statusCode() <= 0 -> {
failure.printStackTrace()
LOGGER.error("Server Error", failure)
response.setStatusCode(HTTPStatusCode.INTERNAL_ERROR.value()).end("")
}
else -> {
failure.printStackTrace()
LOGGER.error("Server Error", failure)
response.setStatusCode(context.statusCode()).end(failure.message ?: "")
}
}
Expand Down

0 comments on commit 6d8bebb

Please sign in to comment.