添加错误处理
This commit is contained in:
parent
162633f003
commit
3f15ae0743
@ -9,6 +9,7 @@ import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.HttpStatusCode
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException
|
||||
import org.springframework.validation.method.MethodValidationException
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
@ -98,7 +99,7 @@ class DefaultExceptionHandler : ResponseEntityExceptionHandler() {
|
||||
return ResponseEntity(Msg(code = -1, msg = ex.message ?: "unknown validation error"), HttpStatus.BAD_REQUEST)
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = [UnauthorizedException::class])
|
||||
@ExceptionHandler(value = [UnauthorizedException::class, UsernameNotFoundException::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