去除敏感报错信息
This commit is contained in:
parent
d43089fad2
commit
6f3ec5a45a
@ -1,6 +1,7 @@
|
|||||||
package dev.surl.surl.handler
|
package dev.surl.surl.handler
|
||||||
|
|
||||||
import dev.surl.surl.common.Msg
|
import dev.surl.surl.common.Msg
|
||||||
|
import dev.surl.surl.common.exception.UnauthorizedExcecption
|
||||||
import dev.surl.surl.common.exception.UserRegistException
|
import dev.surl.surl.common.exception.UserRegistException
|
||||||
import jakarta.validation.ConstraintViolationException
|
import jakarta.validation.ConstraintViolationException
|
||||||
import org.springframework.http.HttpHeaders
|
import org.springframework.http.HttpHeaders
|
||||||
@ -67,7 +68,7 @@ class DefaultExceptionHandler : ResponseEntityExceptionHandler() {
|
|||||||
override fun handleHttpMessageNotReadable(
|
override fun handleHttpMessageNotReadable(
|
||||||
ex: HttpMessageNotReadableException, headers: HttpHeaders, status: HttpStatusCode, request: WebRequest
|
ex: HttpMessageNotReadableException, headers: HttpHeaders, status: HttpStatusCode, request: WebRequest
|
||||||
): ResponseEntity<Any> {
|
): 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>> {
|
fun handleConstraintViolationException(ex: Exception): ResponseEntity<Msg<String>> {
|
||||||
return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unknown validation error"), HttpStatus.BAD_REQUEST)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user