Skip to content

Commit 2d47300

Browse files
authored
release: 1.3.0 (#258)
2 parents 0238c76 + 2122585 commit 2d47300

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

โ€Žsrc/main/kotlin/org/gitanimals/core/advice/GlobalExceptionHandler.ktโ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package org.gitanimals.core.advice
22

33
import org.gitanimals.core.ErrorResponse
4+
import org.slf4j.LoggerFactory
45
import org.springframework.http.HttpStatus
56
import org.springframework.http.ResponseEntity
67
import org.springframework.web.bind.MissingRequestHeaderException
78
import org.springframework.web.bind.annotation.ExceptionHandler
9+
import org.springframework.web.bind.annotation.ResponseStatus
810
import org.springframework.web.bind.annotation.RestControllerAdvice
911

1012
@RestControllerAdvice
1113
class GlobalExceptionHandler {
1214

15+
private val logger = LoggerFactory.getLogger(this::class.simpleName)
16+
1317
@ExceptionHandler(MissingRequestHeaderException::class)
1418
fun handleMissingRequestHeaderException(exception: MissingRequestHeaderException): ResponseEntity<ErrorResponse> {
1519
if (exception.headerName == "Authorization") {
@@ -19,4 +23,11 @@ class GlobalExceptionHandler {
1923

2024
return ResponseEntity.badRequest().body(ErrorResponse.from(exception))
2125
}
26+
27+
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
28+
@ExceptionHandler(IllegalStateException::class)
29+
fun handleIllegalStateException(exception: IllegalStateException): ErrorResponse {
30+
logger.error(exception.message, exception)
31+
return ErrorResponse.from(exception)
32+
}
2233
}

โ€Žsrc/main/kotlin/org/gitanimals/guild/controller/GuildController.ktโ€Ž

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gitanimals.guild.controller
22

3+
import jakarta.servlet.http.HttpServletResponse
34
import org.gitanimals.core.AuthorizationException
45
import org.gitanimals.core.ErrorResponse
56
import org.gitanimals.core.FieldType
@@ -147,20 +148,28 @@ class GuildController(
147148
@GetMapping(value = ["/guilds/{guildId}/draw"], produces = ["image/svg+xml"])
148149
fun draw(
149150
@PathVariable("guildId") guildId: Long,
150-
) = drawGuildFacade.drawGuild(guildId)
151+
response: HttpServletResponse,
152+
): String {
153+
response.cacheControl(3600)
154+
return drawGuildFacade.drawGuild(guildId)
155+
}
151156

152157
@ExceptionHandler(IllegalArgumentException::class)
153158
@ResponseStatus(HttpStatus.BAD_REQUEST)
154159
fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse =
155160
ErrorResponse.from(exception)
156161

157-
@ExceptionHandler(IllegalStateException::class)
158-
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
159-
fun handleIllegalArgumentException(exception: IllegalStateException): ErrorResponse =
160-
ErrorResponse.from(exception)
161-
162162
@ExceptionHandler(AuthorizationException::class)
163163
@ResponseStatus(HttpStatus.UNAUTHORIZED)
164164
fun handleAuthorizationException(exception: AuthorizationException): ErrorResponse =
165165
ErrorResponse.from(exception)
166+
167+
private fun HttpServletResponse.cacheControl(maxAgeSeconds: Int): HttpServletResponse {
168+
this.setHeader(
169+
HttpHeaders.CACHE_CONTROL,
170+
"no-cache, no-store, must-revalidate, max-age=$maxAgeSeconds"
171+
)
172+
this.setHeader(HttpHeaders.PRAGMA, "no-cache")
173+
return this
174+
}
166175
}

โ€Žsrc/main/kotlin/org/gitanimals/render/controller/AnimationController.ktโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AnimationController(
5454
return username.substring(start, end)
5555
}
5656

57-
fun HttpServletResponse.cacheControl(maxAgeSeconds: Int): HttpServletResponse {
57+
private fun HttpServletResponse.cacheControl(maxAgeSeconds: Int): HttpServletResponse {
5858
this.setHeader(
5959
HttpHeaders.CACHE_CONTROL,
6060
"no-cache, no-store, must-revalidate, max-age=$maxAgeSeconds"

โ€Žsrc/main/kotlin/org/gitanimals/render/controller/BackgroundController.ktโ€Ž

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class BackgroundController(
4545
@RequestParam(name = "name") name: String,
4646
) = userFacade.deleteField(token, FieldType.valueOf(name.uppercase()))
4747

48-
@ExceptionHandler(IllegalStateException::class)
49-
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
50-
fun handleIllegalArgumentException(exception: IllegalStateException): ErrorResponse =
51-
ErrorResponse.from(exception)
52-
5348
@ExceptionHandler(IllegalArgumentException::class)
5449
@ResponseStatus(HttpStatus.BAD_REQUEST)
5550
fun handleIllegalArgumentException(illegalArgumentException: IllegalArgumentException): ErrorResponse =

โ€Žsrc/main/kotlin/org/gitanimals/render/controller/PersonaController.ktโ€Ž

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ class PersonaController(
8282
fun handleIllegalArgumentException(exception: IllegalArgumentException): ErrorResponse =
8383
ErrorResponse.from(exception)
8484

85-
@ExceptionHandler(IllegalStateException::class)
86-
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
87-
fun handleIllegalArgumentException(exception: IllegalStateException): ErrorResponse =
88-
ErrorResponse.from(exception)
89-
9085
@ExceptionHandler(AuthorizationException::class)
9186
@ResponseStatus(HttpStatus.UNAUTHORIZED)
9287
fun handleAuthorizationException(exception: AuthorizationException): ErrorResponse =

0 commit comments

Comments
ย (0)