@@ -10,19 +10,19 @@ import ch.megard.akka.http.cors.javadsl.CorsRejection
10
10
import ch .megard .akka .http .cors .scaladsl .CorsDirectives ._
11
11
import ch .megard .akka .http .cors .scaladsl .model .HttpOriginMatcher
12
12
import ch .megard .akka .http .cors .scaladsl .settings .CorsSettings
13
+ import com .typesafe .config .{Config => TypesafeConfig }
13
14
import de .heikoseeberger .akkahttpjson4s .Json4sSupport
14
15
import io .iohk .ethereum .faucet .jsonrpc .FaucetJsonRpcController
15
16
import io .iohk .ethereum .jsonrpc ._
16
- import io .iohk .ethereum .security .SSLError
17
17
import io .iohk .ethereum .jsonrpc .serialization .JsonSerializers
18
18
import io .iohk .ethereum .jsonrpc .server .controllers .JsonRpcBaseController
19
19
import io .iohk .ethereum .jsonrpc .server .http .JsonRpcHttpServer .JsonRpcHttpServerConfig
20
+ import io .iohk .ethereum .security .SSLError
20
21
import io .iohk .ethereum .utils .{ConfigUtils , Logger }
21
22
import javax .net .ssl .SSLContext
22
23
import monix .eval .Task
23
24
import monix .execution .Scheduler .Implicits .global
24
25
import org .json4s .{DefaultFormats , JInt , native }
25
- import com .typesafe .config .{Config => TypesafeConfig }
26
26
27
27
import scala .concurrent .duration .{FiniteDuration , _ }
28
28
@@ -73,10 +73,14 @@ trait JsonRpcHttpServer extends Json4sSupport with RateLimit with Logger {
73
73
}
74
74
75
75
def handleRateLimitedRequest (clientAddress : RemoteAddress , request : JsonRpcRequest ): StandardRoute = {
76
- if (isBelowRateLimit(clientAddress)) {
77
- log.warn(s " Request limit exceeded for ip ${clientAddress.toIP.getOrElse(" unknown" )}" )
76
+ if (isBelowRateLimit(clientAddress))
78
77
complete(jsonRpcController.handleRequest(request).runToFuture)
79
- } else complete(StatusCodes .TooManyRequests )
78
+ else {
79
+ log.warn(s " Request limit exceeded for ip ${clientAddress.toIP.getOrElse(" unknown" )}" )
80
+ complete(
81
+ (StatusCodes .TooManyRequests , JsonRpcError .RateLimitError (config.rateLimit.minRequestInterval.toSeconds))
82
+ )
83
+ }
80
84
}
81
85
82
86
/**
@@ -113,7 +117,7 @@ trait JsonRpcHttpServer extends Json4sSupport with RateLimit with Logger {
113
117
.traverse(requests)(request => jsonRpcController.handleRequest(request))
114
118
.runToFuture
115
119
}
116
- } else complete(StatusCodes .MethodNotAllowed )
120
+ } else complete(StatusCodes .MethodNotAllowed , JsonRpcError . MethodNotFound )
117
121
}
118
122
}
119
123
0 commit comments