抛出处理
This commit is contained in:
parent
0ece4ca76d
commit
3394b01962
|
@ -0,0 +1,32 @@
|
|||
package com.xlf.dromstarkotlin.exception
|
||||
|
||||
import com.frontleaves.general.utils.BaseResponse
|
||||
import com.frontleaves.general.utils.ErrorCode
|
||||
import com.frontleaves.general.utils.ResultUtil
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.http.ResponseEntity
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* 业务自定义抛出
|
||||
*
|
||||
* @since v1.0.0
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
class BusinessException(): RuntimeException() {
|
||||
constructor(errorCode: ErrorCode) : this() {
|
||||
throw RuntimeException(errorCode.output)
|
||||
}
|
||||
|
||||
fun globalReturn(errorMessage: String?, errorCode: ErrorCode, httpServletRequest: HttpServletRequest): ResponseEntity<BaseResponse> {
|
||||
return ResultUtil.error(errorCode, errorMessage, httpServletRequest)
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回前端信息
|
||||
*/
|
||||
fun backInfo(errorCode: ErrorCode, httpServletRequest: HttpServletRequest): ResponseEntity<BaseResponse> {
|
||||
return ResultUtil.error(errorCode, httpServletRequest)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.xlf.dromstarkotlin.exception
|
||||
|
||||
import com.frontleaves.general.utils.BaseResponse
|
||||
import com.frontleaves.general.utils.ErrorCode
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice
|
||||
|
||||
@RestControllerAdvice
|
||||
class BusinessHttpRequestMethodNotSupportedException {
|
||||
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException::class)
|
||||
fun handleCustomException(ignore: HttpRequestMethodNotSupportedException, httpServletRequest: HttpServletRequest): ResponseEntity<BaseResponse> {
|
||||
return BusinessException().globalReturn(ignore.message, ErrorCode.METHOD_NOT_ALLOWED, httpServletRequest)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user