Skip to content

Commit fddccd6

Browse files
committed
change form json format of some endpoints, add BC to some
all POST endpoints now return 400 responses with a body like this: `{"error":{"key":"value",...}}`
1 parent a4ec069 commit fddccd6

7 files changed

+12
-12
lines changed

app/controllers/Analyse.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ final class Analyse(
160160
lila.analyse.ExternalEngine.form
161161
.bindFromRequest()
162162
.fold(
163-
err => badJsonFormError(err),
163+
jsonFormError,
164164
data =>
165165
env.analyse.externalEngine.create(me, data, tokenId.value) map { engine =>
166166
Created(lila.analyse.ExternalEngine.jsonWrites.writes(engine))
@@ -175,7 +175,7 @@ final class Analyse(
175175
lila.analyse.ExternalEngine.form
176176
.bindFromRequest()
177177
.fold(
178-
err => badJsonFormError(err),
178+
jsonFormError,
179179
data =>
180180
env.analyse.externalEngine.update(engine, data) map { engine =>
181181
JsonOk(lila.analyse.ExternalEngine.jsonWrites.writes(engine))

app/controllers/BulkPairing.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class BulkPairing(env: Env) extends LilaController(env):
3030
lila.setup.SetupBulk.form
3131
.bindFromRequest()
3232
.fold(
33-
badJsonFormError,
33+
jsonFormError,
3434
data =>
3535
env.setup.bulk(data, me) flatMap {
3636
case Left(SetupBulk.ScheduleError.RateLimited) =>

app/controllers/Challenge.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final class Challenge(
161161
env.challenge.forms.decline
162162
.bindFromRequest()
163163
.fold(
164-
badJsonFormError,
164+
jsonFormError,
165165
data => api.decline(c, data.realReason) inject jsonOkResult
166166
)
167167
}
@@ -282,7 +282,7 @@ final class Challenge(
282282
!me.is(username) so env.setup.forms.api.user
283283
.bindFromRequest()
284284
.fold(
285-
badJsonFormError,
285+
doubleJsonFormError,
286286
config =>
287287
ChallengeIpRateLimit(req.ipAddress, rateLimitedFu, cost = if me.isApiHog then 0 else 1):
288288
env.user.repo enabledById username flatMap {

app/controllers/Setup.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ final class Setup(
188188
ctx.isMobileOauth || (ctx.isAnon && HTTPRequest.isLichessMobile(ctx.req))
189189
.bindFromRequest()
190190
.fold(
191-
badJsonFormError,
191+
doubleJsonFormError,
192192
config =>
193193
ctx.me.so(env.relation.api.fetchBlocking(_)).flatMap { blocking =>
194194
val uniqId = author.fold(_.value, u => s"sri:${u.id}")

app/controllers/Swiss.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ final class Swiss(
196196
err =>
197197
negotiate(
198198
BadRequest.page(html.swiss.form.edit(swiss, err)),
199-
badJsonFormError(err)
199+
jsonFormError(err)
200200
),
201201
data =>
202202
env.swiss.api.update(swiss.id, data) >> negotiate(
@@ -215,8 +215,8 @@ final class Swiss(
215215
.bindFromRequest()
216216
.fold(
217217
err =>
218-
render.async:
219-
case Accepts.Json() => badJsonFormError(err)
218+
render.async: // TODO
219+
case Accepts.Json() => jsonFormError(err)
220220
case _ => Redirect(routes.Swiss.show(id))
221221
,
222222
date =>

app/controllers/Team.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ final class Team(
271271
.apiRequest(team)
272272
.bindFromRequest()
273273
.fold(
274-
badJsonFormError,
274+
jsonFormError,
275275
setup =>
276276
api.join(team, setup.message, setup.password) flatMap {
277277
case Requesting.Joined => jsonOkResult

app/controllers/Tournament.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ final class Tournament(env: Env, apiC: => Api)(using mat: akka.stream.Materializ
309309
.edit(teams, tour)
310310
.bindFromRequest()
311311
.fold(
312-
badJsonFormError,
312+
jsonFormError,
313313
data =>
314314
api.apiUpdate(tour, data) flatMap { tour =>
315315
jsonView(
@@ -374,7 +374,7 @@ final class Tournament(env: Env, apiC: => Api)(using mat: akka.stream.Materializ
374374
lila.tournament.TeamBattle.DataForm.empty
375375
.bindFromRequest()
376376
.fold(
377-
badJsonFormError,
377+
jsonFormError,
378378
res =>
379379
api.teamBattleUpdate(tour, res, env.team.api.filterExistingIds) >> {
380380
cachedTour(tour.id) map (_ | tour) flatMap { tour =>

0 commit comments

Comments
 (0)