Skip to content

Commit 809a7dd

Browse files
add logs for #2553 in jsonschema.scala
1 parent a01b47c commit 809a7dd

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

otoroshi/app/next/plugins/jsonschema.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ class JsonSchemaRequestValidator extends NgRequestTransformer {
153153
case Right(_) =>
154154
ctx.otoroshiRequest.copy(body = Source.single(rawBody)).right
155155
case Left(errors) =>
156-
JsonSchemaValidator.logger.warn(
157-
s"request body schema validation failed on route '${ctx.route.id}': ${errors.mkString(", ")}"
158-
)
159156
if (config.failOnValidationError) {
157+
JsonSchemaValidator.logger.warn(
158+
s"request body schema validation failed on route '${ctx.route.id}': ${errors.mkString(", ")}"
159+
)
160160
Results
161161
.UnprocessableEntity(
162162
Json.obj(
@@ -166,6 +166,9 @@ class JsonSchemaRequestValidator extends NgRequestTransformer {
166166
)
167167
.left
168168
} else {
169+
JsonSchemaValidator.logger.warn(
170+
s"request body schema validation failed on route '${ctx.route.id}' but fail_on_validation_error is disabled, letting request through: ${errors.mkString(", ")}"
171+
)
169172
ctx.otoroshiRequest.copy(body = Source.single(rawBody)).right
170173
}
171174
}
@@ -212,10 +215,10 @@ class JsonSchemaResponseValidator extends NgRequestTransformer {
212215
case Right(_) =>
213216
ctx.otoroshiResponse.copy(body = Source.single(rawBody)).right
214217
case Left(errors) =>
215-
JsonSchemaValidator.logger.warn(
216-
s"response body schema validation failed on route '${ctx.route.id}': ${errors.mkString(", ")}"
217-
)
218218
if (config.failOnValidationError) {
219+
JsonSchemaValidator.logger.warn(
220+
s"response body schema validation failed on route '${ctx.route.id}': ${errors.mkString(", ")}"
221+
)
219222
Results
220223
.BadGateway(
221224
Json.obj(
@@ -225,6 +228,9 @@ class JsonSchemaResponseValidator extends NgRequestTransformer {
225228
)
226229
.left
227230
} else {
231+
JsonSchemaValidator.logger.warn(
232+
s"response body schema validation failed on route '${ctx.route.id}' but fail_on_validation_error is disabled, letting response through: ${errors.mkString(", ")}"
233+
)
228234
ctx.otoroshiResponse.copy(body = Source.single(rawBody)).right
229235
}
230236
}

0 commit comments

Comments
 (0)