去除敏感报错信息

This commit is contained in:
05412 2024-07-25 18:15:48 +08:00
parent d43089fad2
commit 6f3ec5a45a

View File

@ -1,6 +1,7 @@
package dev.surl.surl.handler
import dev.surl.surl.common.Msg
import dev.surl.surl.common.exception.UnauthorizedExcecption
import dev.surl.surl.common.exception.UserRegistException
import jakarta.validation.ConstraintViolationException
import org.springframework.http.HttpHeaders
@ -67,7 +68,7 @@ class DefaultExceptionHandler : ResponseEntityExceptionHandler() {
override fun handleHttpMessageNotReadable(
ex: HttpMessageNotReadableException, headers: HttpHeaders, status: HttpStatusCode, request: WebRequest
): ResponseEntity<Any> {
return ResponseEntity(Msg<String>(code = -1, msg = ex.message ?: "unknown error"), status)
return ResponseEntity(Msg<Unit>(code = -1, msg = "invalid request body"), status)
}
/**
@ -96,4 +97,9 @@ class DefaultExceptionHandler : ResponseEntityExceptionHandler() {
fun handleConstraintViolationException(ex: Exception): ResponseEntity<Msg<String>> {
return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unknown validation error"), HttpStatus.BAD_REQUEST)
}
@ExceptionHandler(value = [UnauthorizedExcecption::class])
fun handleUnauthorizedException(ex: Exception): ResponseEntity<Msg<String>> {
return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unauthorized"), HttpStatus.UNAUTHORIZED)
}
}