Build: enable ktlint+detekt, format sources, add core unit tests
This commit is contained in:
@@ -6,7 +6,6 @@ import org.springframework.context.annotation.Bean
|
||||
|
||||
@AutoConfiguration
|
||||
class LmsCommonAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
fun lmsExceptionHandler(): LmsExceptionHandler = LmsExceptionHandler()
|
||||
|
||||
@@ -13,17 +13,27 @@ open class LmsException(
|
||||
val violations: List<FieldViolation> = emptyList(),
|
||||
) : RuntimeException(message)
|
||||
|
||||
class BadRequestException(message: String, code: String? = null) :
|
||||
LmsException(HttpStatus.BAD_REQUEST, message, code)
|
||||
class BadRequestException(
|
||||
message: String,
|
||||
code: String? = null,
|
||||
) : LmsException(HttpStatus.BAD_REQUEST, message, code)
|
||||
|
||||
class NotFoundException(message: String, code: String? = null) :
|
||||
LmsException(HttpStatus.NOT_FOUND, message, code)
|
||||
class NotFoundException(
|
||||
message: String,
|
||||
code: String? = null,
|
||||
) : LmsException(HttpStatus.NOT_FOUND, message, code)
|
||||
|
||||
class ConflictException(message: String, code: String? = null) :
|
||||
LmsException(HttpStatus.CONFLICT, message, code)
|
||||
class ConflictException(
|
||||
message: String,
|
||||
code: String? = null,
|
||||
) : LmsException(HttpStatus.CONFLICT, message, code)
|
||||
|
||||
class ForbiddenException(message: String, code: String? = null) :
|
||||
LmsException(HttpStatus.FORBIDDEN, message, code)
|
||||
class ForbiddenException(
|
||||
message: String,
|
||||
code: String? = null,
|
||||
) : LmsException(HttpStatus.FORBIDDEN, message, code)
|
||||
|
||||
class UnauthorizedException(message: String, code: String? = null) :
|
||||
LmsException(HttpStatus.UNAUTHORIZED, message, code)
|
||||
class UnauthorizedException(
|
||||
message: String,
|
||||
code: String? = null,
|
||||
) : LmsException(HttpStatus.UNAUTHORIZED, message, code)
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice
|
||||
|
||||
@RestControllerAdvice
|
||||
class LmsExceptionHandler {
|
||||
|
||||
@ExceptionHandler(LmsException::class)
|
||||
fun handleDomain(ex: LmsException): ResponseEntity<ApiError> =
|
||||
ResponseEntity.status(ex.status).body(
|
||||
@@ -22,9 +21,10 @@ class LmsExceptionHandler {
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException::class)
|
||||
fun handleValidation(ex: MethodArgumentNotValidException): ResponseEntity<ApiError> {
|
||||
val violations = ex.bindingResult.fieldErrors.map {
|
||||
FieldViolation(field = it.field, message = it.defaultMessage ?: "invalid value")
|
||||
}
|
||||
val violations =
|
||||
ex.bindingResult.fieldErrors.map {
|
||||
FieldViolation(field = it.field, message = it.defaultMessage ?: "invalid value")
|
||||
}
|
||||
return ResponseEntity.badRequest().body(
|
||||
ApiError(
|
||||
title = "Validation failed",
|
||||
|
||||
Reference in New Issue
Block a user