Added an exception mapper that prints out errors emitted by the webserver ()

Added an exception mapper that prints out errors emitted by the JAX-RS server to aid debugging.
This commit is contained in:
Clinton 2017-04-04 15:43:55 +01:00 committed by GitHub
parent 23224fc92c
commit a93692e434
2 changed files with 20 additions and 2 deletions
webserver/src/main/kotlin/net/corda/webserver/internal

View File

@ -1,13 +1,12 @@
package net.corda.webserver.internal
import net.corda.core.messaging.CordaRPCOps
import net.corda.webserver.api.*
import net.corda.webserver.api.APIServer
import java.time.LocalDateTime
import java.time.ZoneId
import javax.ws.rs.core.Response
class APIServerImpl(val rpcOps: CordaRPCOps) : APIServer {
override fun serverTime(): LocalDateTime {
return LocalDateTime.ofInstant(rpcOps.currentNodeTime(), ZoneId.of("UTC"))
}

View File

@ -0,0 +1,19 @@
package net.corda.webserver.internal
import net.corda.core.utilities.loggerFor
import javax.ws.rs.core.Response
import javax.ws.rs.ext.ExceptionMapper
import javax.ws.rs.ext.Provider
// Provides basic exception logging to all APIs
@Provider
class AllExceptionMapper: ExceptionMapper<Exception> {
companion object {
val logger = loggerFor<APIServerImpl>()
}
override fun toResponse(exception: Exception?): Response {
logger.error("Unhandled exception in API", exception)
return Response.status(500).build()
}
}