Skip to content

Commit

Permalink
refactor: move controller advice for validation errors up to common s…
Browse files Browse the repository at this point in the history
…uper directory #46

ohsome-contributions-stats-service: 'Consider introducing 'Jakarta Bean validation' standard '
#46
  • Loading branch information
mmerdes committed Feb 6, 2024
1 parent 5d963a5 commit be92702
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.heigit.ohsome.now.statsservice.stats
package org.heigit.ohsome.now.statsservice

import jakarta.validation.ConstraintViolationException
import org.springframework.http.HttpStatus.BAD_REQUEST
Expand All @@ -8,13 +8,11 @@ import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.ResponseStatus


// see https://reflectoring.io/bean-validation-with-spring-boot/#handling-validation-errors
//class ValidationErrorResponse(val violations: List<Violation>)
// inspired by https://reflectoring.io/bean-validation-with-spring-boot/#handling-validation-errors


class Violation(val message: String, val invalidValue: String)

class Violation(
val message: String,
val invalidValue: String
)

@ControllerAdvice
internal class ErrorHandlingControllerAdvice {
Expand All @@ -25,7 +23,6 @@ internal class ErrorHandlingControllerAdvice {
fun onConstraintValidationException(validationError: ConstraintViolationException) = validationError
.constraintViolations
.map { Violation(it.message, it.invalidValue.toString()) }
// .let { ValidationErrorResponse(it) }

}

Expand Down

0 comments on commit be92702

Please sign in to comment.