diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessException.kt b/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessException.kt new file mode 100644 index 0000000..f544c07 --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessException.kt @@ -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 { + return ResultUtil.error(errorCode, errorMessage, httpServletRequest) + } + + /** + * 返回前端信息 + */ + fun backInfo(errorCode: ErrorCode, httpServletRequest: HttpServletRequest): ResponseEntity { + return ResultUtil.error(errorCode, httpServletRequest) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessHttpRequestMethodNotSupportedException.kt b/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessHttpRequestMethodNotSupportedException.kt new file mode 100644 index 0000000..2fa0f28 --- /dev/null +++ b/src/main/kotlin/com/xlf/dromstarkotlin/exception/BusinessHttpRequestMethodNotSupportedException.kt @@ -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 { + return BusinessException().globalReturn(ignore.message, ErrorCode.METHOD_NOT_ALLOWED, httpServletRequest) + } +} \ No newline at end of file