Skip to content

Commit

Permalink
Merge pull request #284 from ekino/chore/gradle-8-1-1
Browse files Browse the repository at this point in the history
chore: upgrade gradle to 8.1.1
  • Loading branch information
clemstoquart authored May 12, 2023
2 parents 2e51e93 + 2c0ee32 commit ceb88bc
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ max_line_length=150
trim_trailing_whitespace=true

[*.{kt,kts}]
disabled_rules=import-ordering,no-wildcard-imports,indent
ktlint_disabled_rules=import-ordering,indent
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ val kotlinVersion = "1.7.20"
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") // required by kotlin("jvm")
implementation("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion") // required by kotlin("plugin.spring")
implementation("gradle.plugin.com.ekino.oss.plugin:kotlin-quality-plugin:3.2.0") // required by id("com.ekino.oss.plugin.kotlin-quality")
implementation("com.ekino.oss.plugin:kotlin-quality-plugin:4.1.0") // required by id("com.ekino.oss.plugin.kotlin-quality")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:$kotlinVersion") // required by id("org.jetbrains.dokka")
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class RestExceptionHandlerTest(
fun `should get no such key exception`() {
mockMvc.perform(get("$RESOLVED_ERROR_PATH/no-such-key-exception"))
.andExpect(status().isNotFound)
.andExpect(content().string(
jsonMatcher("""
.andExpect(
content().string(
jsonMatcher(
"""
{
"status": 404,
"code": "error.not_found",
Expand All @@ -34,7 +36,9 @@ class RestExceptionHandlerTest(
"stacktrace": "",
"timestamp": "{#date_time_format:iso_instant#}"
}
""".trimIndent())
))
""".trimIndent()
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class RestExceptionHandlerTest(
fun `should get not found error`() {
mockMvc.perform(get("$RESOLVED_ERROR_PATH/notFound"))
.andExpect(status().isNotFound)
.andExpect(MockMvcResultMatchers.content().string(
jsonMatcher("""
.andExpect(
MockMvcResultMatchers.content().string(
jsonMatcher(
"""
{
"status": 404,
"code": "error.not_found",
Expand All @@ -35,17 +37,23 @@ class RestExceptionHandlerTest(
"stacktrace": "",
"timestamp": "{#date_time_format:iso_instant#}"
}
""".trimIndent())
))
""".trimIndent()
)
)
)
}

@Test
fun `should get repository constraint validation error`() {
mockMvc.perform(get("$RESOLVED_ERROR_PATH/repository-constraint-validation")
.accept(MediaType.APPLICATION_JSON))
mockMvc.perform(
get("$RESOLVED_ERROR_PATH/repository-constraint-validation")
.accept(MediaType.APPLICATION_JSON)
)
.andExpect(status().isBadRequest)
.andExpect(MockMvcResultMatchers.content().string(
jsonMatcher("""
.andExpect(
MockMvcResultMatchers.content().string(
jsonMatcher(
"""
{
"status": 400,
"code": "error.invalid",
Expand All @@ -69,7 +77,9 @@ class RestExceptionHandlerTest(
"stacktrace": "",
"timestamp": "{#date_time_format:iso_instant#}"
}
""".trimIndent())
))
""".trimIndent()
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@ import org.springframework.http.HttpStatus
import java.time.Instant

fun notFound(service: String, devMessage: String?, stacktrace: String): ErrorBody {
return toError(service, HttpStatus.NOT_FOUND, DefaultErrorCode.NOT_FOUND.value(), HttpStatus.NOT_FOUND.reasonPhrase,
devMessage, stacktrace, emptyList(), emptyList())
return toError(
service,
HttpStatus.NOT_FOUND,
DefaultErrorCode.NOT_FOUND.value(),
HttpStatus.NOT_FOUND.reasonPhrase,
devMessage,
stacktrace,
emptyList(),
emptyList()
)
}

fun unavailable(service: String, code: String, devMessage: String?, stacktrace: String): ErrorBody {
return toError(
service, HttpStatus.SERVICE_UNAVAILABLE, code, HttpStatus.SERVICE_UNAVAILABLE.reasonPhrase,
devMessage, stacktrace, emptyList(), emptyList()
service,
HttpStatus.SERVICE_UNAVAILABLE,
code,
HttpStatus.SERVICE_UNAVAILABLE.reasonPhrase,
devMessage,
stacktrace,
emptyList(),
emptyList()
)
}

Expand All @@ -40,13 +54,28 @@ fun badRequest(

fun methodNotAllowed(service: String, code: String, devMessage: String?, stacktrace: String): ErrorBody {
return toError(
service, HttpStatus.METHOD_NOT_ALLOWED, code, HttpStatus.METHOD_NOT_ALLOWED.reasonPhrase, devMessage, stacktrace, emptyList(), emptyList()
service,
HttpStatus.METHOD_NOT_ALLOWED,
code,
HttpStatus.METHOD_NOT_ALLOWED.reasonPhrase,
devMessage,
stacktrace,
emptyList(),
emptyList()
)
}

fun conflict(service: String, devMessage: String?, stacktrace: String): ErrorBody {
return toError(service, HttpStatus.CONFLICT, DefaultErrorCode.CONFLICT.value(), HttpStatus.CONFLICT.reasonPhrase,
devMessage, stacktrace, emptyList(), emptyList())
return toError(
service,
HttpStatus.CONFLICT,
DefaultErrorCode.CONFLICT.value(),
HttpStatus.CONFLICT.reasonPhrase,
devMessage,
stacktrace,
emptyList(),
emptyList()
)
}

fun preconditionFailed(service: String, devMessage: String, stacktrace: String): ErrorBody {
Expand All @@ -58,24 +87,46 @@ fun preconditionFailed(service: String, devMessage: String, stacktrace: String):
devMessage,
stacktrace,
emptyList(),
emptyList())
emptyList()
)
}

fun conflict(service: String, devMessage: String, stacktrace: String, errors: List<ValidationErrorBody>): ErrorBody {
return toError(
service, HttpStatus.CONFLICT, DefaultErrorCode.CONFLICT.value(), HttpStatus.CONFLICT.reasonPhrase, devMessage, stacktrace, errors, emptyList()
service,
HttpStatus.CONFLICT,
DefaultErrorCode.CONFLICT.value(),
HttpStatus.CONFLICT.reasonPhrase,
devMessage,
stacktrace,
errors,
emptyList()
)
}

fun unprocessableEntity(service: String, code: String, devMessage: String, stacktrace: String, errors: List<ValidationErrorBody>): ErrorBody {
return toError(
service, HttpStatus.UNPROCESSABLE_ENTITY, code, HttpStatus.UNPROCESSABLE_ENTITY.reasonPhrase, devMessage, stacktrace, errors, emptyList()
service,
HttpStatus.UNPROCESSABLE_ENTITY,
code,
HttpStatus.UNPROCESSABLE_ENTITY.reasonPhrase,
devMessage,
stacktrace,
errors,
emptyList()
)
}

fun unsupportedMediaType(service: String, code: String, devMessage: String?, stacktrace: String): ErrorBody {
return toError(
service, HttpStatus.UNSUPPORTED_MEDIA_TYPE, code, HttpStatus.UNSUPPORTED_MEDIA_TYPE.reasonPhrase, devMessage, stacktrace, emptyList(), emptyList()
service,
HttpStatus.UNSUPPORTED_MEDIA_TYPE,
code,
HttpStatus.UNSUPPORTED_MEDIA_TYPE.reasonPhrase,
devMessage,
stacktrace,
emptyList(),
emptyList()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ abstract class CoreExceptionHandler(
fun handleUnavailableServiceException(req: HttpServletRequest, e: Exception): ResponseEntity<ErrorBody> {
log.error("Unavailable service : ", e)
return unavailable(
req.toServiceName(applicationName), "error.unavailable", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.unavailable",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}

Expand Down Expand Up @@ -79,7 +82,11 @@ abstract class CoreExceptionHandler(
val errors = e.constraintViolations?.map { it.toValidationErrorBody() } ?: emptyList()

return badRequest(
req.toServiceName(applicationName), INVALID_ERROR_PREFIX, e.message, e.toStacktrace(properties.displayFullStacktrace), errors
req.toServiceName(applicationName),
INVALID_ERROR_PREFIX,
e.message,
e.toStacktrace(properties.displayFullStacktrace),
errors
).toErrorResponse()
}

Expand All @@ -91,11 +98,18 @@ abstract class CoreExceptionHandler(
val validationErrorBody = listOf(cause.toEnumValidationErrorBody())
val message = "The value '${cause.value}' is not an accepted value"
badRequest(
req.toServiceName(applicationName), "error.invalid.enum", message, e.toStacktrace(properties.displayFullStacktrace), validationErrorBody
req.toServiceName(applicationName),
"error.invalid.enum",
message,
e.toStacktrace(properties.displayFullStacktrace),
validationErrorBody
).toErrorResponse()
} else {
badRequest(
req.toServiceName(applicationName), "error.not_readable_json", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.not_readable_json",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}
}
Expand All @@ -108,11 +122,18 @@ abstract class CoreExceptionHandler(
val validationErrorBody = listOf(e.toEnumValidationErrorBody())
val message = "The value '${e.value}' is not an accepted value"
badRequest(
req.toServiceName(applicationName), "error.invalid.enum", message, e.toStacktrace(properties.displayFullStacktrace), validationErrorBody
req.toServiceName(applicationName),
"error.invalid.enum",
message,
e.toStacktrace(properties.displayFullStacktrace),
validationErrorBody
).toErrorResponse()
} else {
badRequest(
req.toServiceName(applicationName), "error.argument_type_mismatch", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.argument_type_mismatch",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}
}
Expand All @@ -121,15 +142,21 @@ abstract class CoreExceptionHandler(
fun handleMissingServletRequestParameterException(req: HttpServletRequest, e: MissingServletRequestParameterException): ResponseEntity<ErrorBody> {
log.debug("Missing parameter : ", e)
return badRequest(
req.toServiceName(applicationName), "error.missing_parameter", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.missing_parameter",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}

@ExceptionHandler(HttpRequestMethodNotSupportedException::class)
fun handleMethodNotSupportedException(req: HttpServletRequest, e: HttpRequestMethodNotSupportedException): ResponseEntity<ErrorBody> {
log.debug("Method not supported : ", e)
return methodNotAllowed(
req.toServiceName(applicationName), "error.method_not_allowed", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.method_not_allowed",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}

Expand All @@ -143,7 +170,10 @@ abstract class CoreExceptionHandler(
fun handleHttpMediaTypeNotSupportedException(req: HttpServletRequest, e: HttpMediaTypeNotSupportedException): ResponseEntity<ErrorBody> {
log.debug("Media type not supported : ", e)
return unsupportedMediaType(
req.toServiceName(applicationName), "error.media_type_not_supported", e.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
"error.media_type_not_supported",
e.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}

Expand All @@ -159,8 +189,11 @@ abstract class CoreExceptionHandler(
val message = responseStatus?.reason ?: e.toMessage()

return defaultError(
req.toServiceName(applicationName), status, "error." + e.javaClass.simpleName.camelToSnakeCase(),
message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
status,
"error." + e.javaClass.simpleName.camelToSnakeCase(),
message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ abstract class DataRestExceptionHandler(
e: RepositoryConstraintViolationException,
req: HttpServletRequest
): ResponseEntity<ErrorBody> {

log.debug("Constraint violation errors : ", e)

val errors = e.errors.fieldErrors.map { it.toValidationErrorBody() }
val globalErrors = e.errors.globalErrors.map { it.toValidationErrorBody() }

return badRequest(
req.toServiceName(applicationName), INVALID_ERROR_PREFIX, e.message, e.toStacktrace(properties.displayFullStacktrace), errors, globalErrors
req.toServiceName(applicationName),
INVALID_ERROR_PREFIX,
e.message,
e.toStacktrace(properties.displayFullStacktrace),
errors,
globalErrors
).toErrorResponse()
}

Expand All @@ -56,7 +60,9 @@ abstract class DataRestExceptionHandler(
val cause = e.cause
if (cause is JDBCException) {
return conflict(
req.toServiceName(applicationName), cause.sqlException.message, e.toStacktrace(properties.displayFullStacktrace)
req.toServiceName(applicationName),
cause.sqlException.message,
e.toStacktrace(properties.displayFullStacktrace)
).toErrorResponse()
}
return conflict(req.toServiceName(applicationName), e.message, e.toStacktrace(properties.displayFullStacktrace)).toErrorResponse()
Expand Down
Loading

0 comments on commit ceb88bc

Please sign in to comment.