Improve error logging on server (#4896)

This commit is contained in:
Chris Stewart 2022-11-22 14:46:24 -06:00 committed by GitHub
parent 6a0df4ee14
commit e993335f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ import akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller
import akka.stream.scaladsl.{Flow, Keep, Sink, Source} import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import akka.{Done, NotUsed} import akka.{Done, NotUsed}
import de.heikoseeberger.akkahttpupickle.UpickleSupport._ import de.heikoseeberger.akkahttpupickle.UpickleSupport._
import grizzled.slf4j.Logging
import org.bitcoins.commons.config.AppConfig import org.bitcoins.commons.config.AppConfig
import org.bitcoins.commons.jsonmodels.ws.WsNotification import org.bitcoins.commons.jsonmodels.ws.WsNotification
import org.bitcoins.server.util.{ServerBindings, WsServerConfig} import org.bitcoins.server.util.{ServerBindings, WsServerConfig}
@ -73,7 +74,7 @@ case class Server(
Server.httpError(s"'$method' is not a valid method", Server.httpError(s"'$method' is not a valid method",
StatusCodes.BadRequest)) StatusCodes.BadRequest))
case err: Throwable => case err: Throwable =>
logger.info(s"Unhandled error in server:", err) logger.error(s"Unhandled error in server:", err)
complete(Server.httpError(err.getMessage)) complete(Server.httpError(err.getMessage))
} }
@ -226,7 +227,7 @@ case class Server(
} }
object Server { object Server extends Logging {
// TODO id parameter // TODO id parameter
case class Response( case class Response(
@ -278,18 +279,14 @@ object Server {
} }
def httpBadRequest(ex: Throwable): HttpResponse = { def httpBadRequest(ex: Throwable): HttpResponse = {
httpBadRequest(ex.getMessage) logger.error(s"Http bad request", ex)
} val msg = ex.getMessage
def httpBadRequest(msg: String): HttpResponse = {
val entity = httpError(msg) val entity = httpError(msg)
HttpResponse(status = StatusCodes.BadRequest, entity = entity) HttpResponse(status = StatusCodes.BadRequest, entity = entity)
} }
def httpError( def httpError(msg: String, status: StatusCode): HttpResponse = {
msg: String, logger.error(s"Http error msg=$msg statusCode=$status")
status: StatusCode = StatusCodes.InternalServerError): HttpResponse = {
val entity = { val entity = {
val response = Response(error = Some(msg)) val response = Response(error = Some(msg))
HttpEntity( HttpEntity(