-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...in/org/gitanimals/render/app/Exception.kt → ...n/kotlin/org/gitanimals/core/Exception.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package org.gitanimals.render.app | ||
package org.gitanimals.core | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
class AuthorizationException(message: String) : IllegalArgumentException(message) | ||
|
||
val AUTHORIZATION_EXCEPTION = AuthorizationException("Authorization fail") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/org/gitanimals/guild/controller/response/ErrorResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.gitanimals.guild.controller.response | ||
|
||
data class ErrorResponse( | ||
val message: String, | ||
) { | ||
|
||
companion object { | ||
fun from(exception: Exception): ErrorResponse = | ||
ErrorResponse(exception.message ?: exception.localizedMessage) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/org/gitanimals/guild/infra/HttpClientErrorHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.gitanimals.guild.infra | ||
|
||
import org.gitanimals.core.AuthorizationException | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.client.ClientHttpResponse | ||
import org.springframework.web.client.ResponseErrorHandler | ||
|
||
|
||
class HttpClientErrorHandler : ResponseErrorHandler { | ||
|
||
override fun hasError(response: ClientHttpResponse): Boolean { | ||
return response.statusCode.isError | ||
} | ||
|
||
override fun handleError(response: ClientHttpResponse) { | ||
val body = response.body.bufferedReader().use { it.readText() } | ||
when { | ||
response.statusCode.isSameCodeAs(HttpStatus.UNAUTHORIZED) -> | ||
throw AuthorizationException(body) | ||
|
||
response.statusCode.is4xxClientError -> | ||
throw IllegalArgumentException(body) | ||
|
||
response.statusCode.is5xxServerError -> | ||
throw IllegalStateException(body) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/org/gitanimals/render/controller/InternalPersonaController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters