添加通用返回响应和异常

This commit is contained in:
huangge1199 2025-06-27 16:36:50 +08:00
parent f5e1dfb225
commit 45879ba6f0
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package com.huangge1199.picture.common;
import com.huangge1199.picture.exception.ErrorCode;
import java.io.Serializable;
/**
* R
*
* @author huangge1199
* @since 2025/6/27 16:24:58
*/
public class R<T> implements Serializable {
private int code;
private T data;
private String message;
public R(int code, T data, String message) {
this.code = code;
this.data = data;
this.message = message;
}
public R(int code, T data) {
this(code, data, "");
}
public R(ErrorCode errorCode) {
this(errorCode.getCode(), null, errorCode.getMessage());
}
}

View File

@ -0,0 +1,38 @@
package com.huangge1199.picture.exception;
import lombok.Getter;
/**
* ErrorCode
*
* @author huangge1199
* @since 2025/6/27 16:26:54
*/
@Getter
public enum ErrorCode {
SUCCESS(200, "ok"),
PARAMS_ERROR(40000, "请求参数错误"),
NOT_LOGIN_ERROR(40100, "未登录"),
NO_AUTH_ERROR(40101, "无权限"),
NOT_FOUND_ERROR(40400, "请求数据不存在"),
FORBIDDEN_ERROR(40300, "禁止访问"),
SYSTEM_ERROR(50000, "系统内部异常"),
OPERATION_ERROR(50001, "操作失败");
/**
* 状态码
*/
private final int code;
/**
* 信息
*/
private final String message;
ErrorCode(int code, String message) {
this.code = code;
this.message = message;
}
}