Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
log request end also for unthrottled api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mavilein committed Feb 22, 2018
1 parent f078805 commit f749d51
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions server/api/src/main/scala/com/prisma/api/server/ApiServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,36 @@ case class ApiServer(
}

def unthrottledCall(projectId: ProjectId, rawRequest: RawRequest) = {
val result = apiDependencies.requestHandler.handleRawRequestForPublicApi(projectId.asString, rawRequest)
val result = handleRequestForPublicApi(projectId, rawRequest)
complete(result)
}

def throttledCall(projectId: ProjectId, rawRequest: RawRequest, throttler: Throttler[ProjectId]) = {
val result = throttler.throttled(projectId) { () =>
apiDependencies.requestHandler.handleRawRequestForPublicApi(projectId.asString, rawRequest)
handleRequestForPublicApi(projectId, rawRequest)
}
onComplete(result) {
case scala.util.Success(result) =>
logRequestEnd(projectId.asString)
respondWithHeader(RawHeader("Throttled-By", result.throttledBy.toString + "ms")) {
complete(result.result)
}

case scala.util.Failure(_: ThrottleBufferFullException) =>
logRequestEnd(projectId.asString)
throw ThrottlerBufferFullException()

case scala.util.Failure(exception) => // just propagate the exception
logRequestEnd(projectId.asString)
throw exception
}
}

def handleRequestForPublicApi(projectId: ProjectId, rawRequest: RawRequest) = {
val result = apiDependencies.requestHandler.handleRawRequestForPublicApi(projectId.asString, rawRequest)
result.onComplete { _ =>
logRequestEnd(projectId.asString)
}
result
}

logger.info(Json.toJson(LogData(LogKey.RequestNew, requestId)).toString())
pathPrefix(Segments(min = 2, max = 4)) { segments =>
post {
Expand Down

0 comments on commit f749d51

Please sign in to comment.