package com.custom.webui.exception; import lombok.Getter; /** * 业务异常。由 {@link GlobalExceptionHandler} 统一转换成 {@code Result} 结构。 * *
用 HTTP 状态码表达语义:401 未认证、403 无权限、404 不存在、400 参数错误、500 服务端错误。 */ @Getter public class BusinessException extends RuntimeException { private final int code; public BusinessException(int code, String message) { super(message); this.code = code; } public static BusinessException badRequest(String message) { return new BusinessException(400, message); } public static BusinessException unauthorized(String message) { return new BusinessException(401, message); } public static BusinessException forbidden(String message) { return new BusinessException(403, message); } public static BusinessException notFound(String message) { return new BusinessException(404, message); } public static BusinessException serverError(String message) { return new BusinessException(500, message); } }