[F] Fix mai2 error response

This commit is contained in:
Azalea
2024-03-27 23:05:46 -04:00
parent b7d2a97f05
commit b3fcf8dd5e
2 changed files with 28 additions and 18 deletions

View File

@@ -13,13 +13,15 @@ class ApiException(val code: Int, message: Str) : RuntimeException(message) {
companion object {
val log = LoggerFactory.getLogger(ApiException::class.java)
}
fun resp() = ResponseEntity.status(code).body(message.toString())
}
@ControllerAdvice
@ControllerAdvice(basePackages = ["icu.samnyan"])
class GlobalExceptionHandler {
@ExceptionHandler(ApiException::class)
fun handleCustomApiException(e: ApiException): ResponseEntity<Any?> {
fun handleCustomApiException(e: ApiException): ResponseEntity<String> {
// On error, return the error code and message
return ResponseEntity.status(e.code).body(e.message)
return e.resp()
}
}