mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
return error as json when rate limit reached or user not found
This commit is contained in:
parent
80ff9bfe6d
commit
644a106a31
@ -68,16 +68,17 @@ class Server(port: Int){
|
||||
host.addContext("/v1/captcha",(req, resp) => {
|
||||
val accessToken = Option(req.getHeaders().get("access-token")).map(_.toInt)
|
||||
val access = accessToken.map(t => rateLimiter.validateUser(t) && rateLimiter.checkLimit(t)).getOrElse(false)
|
||||
val id = if(access){
|
||||
if(access){
|
||||
val body = req.getJson()
|
||||
val json = parse(body)
|
||||
val param = json.extract[Parameters]
|
||||
captcha.getChallenge(param)
|
||||
val id = captcha.getChallenge(param)
|
||||
resp.getHeaders().add("Content-Type","application/json")
|
||||
resp.send(200, write(id))
|
||||
} else {
|
||||
"Not a valid user or rate limit reached!"
|
||||
resp.getHeaders().add("Content-Type","application/json")
|
||||
resp.send(400, write("""{"error": "Not a valid user or rate limit reached!"}"""))
|
||||
}
|
||||
resp.getHeaders().add("Content-Type","application/json")
|
||||
resp.send(200, write(id))
|
||||
0
|
||||
},"POST")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user