-
Notifications
You must be signed in to change notification settings - Fork 1
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
6 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
server/api/src/main/kotlin/com/kw/api/common/dto/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,6 @@ | ||
package com.kw.api.common.dto.response | ||
|
||
class ErrorResponse( | ||
val code: String, | ||
val message: String | ||
) |
17 changes: 17 additions & 0 deletions
17
server/api/src/main/kotlin/com/kw/api/common/exception/CustomErrorCode.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,17 @@ | ||
package com.kw.api.common.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
enum class CustomErrorCode( | ||
val status: HttpStatus, | ||
val code: String, | ||
val message: String | ||
) { | ||
|
||
FORBIDDEN_BUNDLE(HttpStatus.FORBIDDEN, "FORBIDDEN_BUNDLE", "비공개 꾸러미입니다."), | ||
NOT_FOUND_BUNDLE(HttpStatus.NOT_FOUND, "NOT_FOUND_BUNDLE", "존재하지 않는 꾸러미입니다."), | ||
NOT_FOUND_QUESTION(HttpStatus.NOT_FOUND, "NOT_FOUND_QUESTION", "존재하지 않는 질문입니다."), | ||
|
||
INCLUDE_NOT_FOUND_TAG(HttpStatus.NOT_FOUND, "INCLUDE_NOT_FOUND_TAG", "존재하지 않는 태그가 포함되어 있습니다."), | ||
INCLUDE_NOT_FOUND_QUESTION(HttpStatus.NOT_FOUND, "INCLUDE_NOT_FOUND_QUESTION", "존재하지 않는 질문이 포함되어 있습니다."), | ||
} |
16 changes: 16 additions & 0 deletions
16
server/api/src/main/kotlin/com/kw/api/common/exception/CustomException.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,16 @@ | ||
package com.kw.api.common.exception | ||
|
||
import com.kw.api.common.dto.response.ErrorResponse | ||
import org.springframework.http.HttpStatus | ||
|
||
class CustomException(private val errorCode: CustomErrorCode) : RuntimeException() { | ||
|
||
fun getErrorResponse(): ErrorResponse { | ||
return ErrorResponse(this.errorCode.code, this.errorCode.message) | ||
} | ||
|
||
fun getStatus(): HttpStatus { | ||
return this.errorCode.status | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
server/api/src/main/kotlin/com/kw/api/common/exception/CustomExceptionHandler.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,17 @@ | ||
package com.kw.api.common.exception | ||
|
||
import com.kw.api.common.dto.response.ErrorResponse | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler | ||
|
||
@RestControllerAdvice | ||
class CustomExceptionHandler : ResponseEntityExceptionHandler() { | ||
|
||
@ExceptionHandler(CustomException::class) | ||
protected fun handleCustomException(ex: CustomException): ResponseEntity<ErrorResponse> { | ||
return ResponseEntity.status(ex.getStatus()).body(ex.getErrorResponse()) | ||
} | ||
|
||
} |
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