diff options
Diffstat (limited to 'src/main/scala/xyz/driver/core')
-rw-r--r-- | src/main/scala/xyz/driver/core/logging.scala | 2 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/rest.scala | 33 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/main/scala/xyz/driver/core/logging.scala b/src/main/scala/xyz/driver/core/logging.scala index ba17131..c8fb6ae 100644 --- a/src/main/scala/xyz/driver/core/logging.scala +++ b/src/main/scala/xyz/driver/core/logging.scala @@ -131,7 +131,7 @@ object logging { val date = new SimpleDateFormat(DateFormatString).format(new Date(loggingEvent.getTimeStamp)) val level = StringUtils.rightPad(loggingEvent.getLevel.toString, 5) - val message = new StringBuilder(s"$date [$level] - loggingEvent.getMessage$newline") + val message = new StringBuilder(s"$date [$level] - ${loggingEvent.getMessage}$newline") logContext(message, loggingEvent) diff --git a/src/main/scala/xyz/driver/core/rest.scala b/src/main/scala/xyz/driver/core/rest.scala index da6df96..945e3be 100644 --- a/src/main/scala/xyz/driver/core/rest.scala +++ b/src/main/scala/xyz/driver/core/rest.scala @@ -148,7 +148,7 @@ object rest { protected implicit val materializer = ActorMaterializer()(actorSystem) protected implicit val execution = executionContext - def sendRequest(context: ServiceRequestContext)(requestStub: HttpRequest): Future[Unmarshal[ResponseEntity]] = { + def sendRequestGetResponse(context: ServiceRequestContext)(requestStub: HttpRequest): Future[HttpResponse] = { val requestTime = time.currentTime() @@ -158,30 +158,35 @@ object rest { log.audit(s"Sending to ${request.uri} request $request with tracking id ${context.trackingId}") - val responseEntity = Http()(actorSystem).singleRequest(request)(materializer) map { response => - if(response.status == StatusCodes.NotFound) { - Unmarshal(HttpEntity.Empty: ResponseEntity) - } else if(response.status.isFailure()) { - throw new Exception(s"Http status is failure ${response.status}") - } else { - Unmarshal(response.entity) - } - } + val response = Http()(actorSystem).singleRequest(request)(materializer) - responseEntity.onComplete { + response.onComplete { case Success(r) => val responseTime = time.currentTime() - log.audit(s"Response from ${request.uri} to request $requestStub is successful") + log.audit(s"Response from ${request.uri} to request $requestStub is successful: $r") stats.recordStats(Seq("request", request.uri.toString, "success"), TimeRange(requestTime, responseTime), 1) case Failure(t: Throwable) => val responseTime = time.currentTime() - log.audit(s"Failed to receive response from ${request.uri} to request $requestStub") + log.audit(s"Failed to receive response from ${request.uri} to request $requestStub", t) log.error(s"Failed to receive response from ${request.uri} to request $requestStub", t) stats.recordStats(Seq("request", request.uri.toString, "fail"), TimeRange(requestTime, responseTime), 1) } (executionContext) - responseEntity + response + } + + def sendRequest(context: ServiceRequestContext)(requestStub: HttpRequest): Future[Unmarshal[ResponseEntity]] = { + + sendRequestGetResponse(context)(requestStub) map { response => + if(response.status == StatusCodes.NotFound) { + Unmarshal(HttpEntity.Empty: ResponseEntity) + } else if(response.status.isFailure()) { + throw new Exception(s"Http status is failure ${response.status}") + } else { + Unmarshal(response.entity) + } + } } } |