63 lines
1.6 KiB
Java
63 lines
1.6 KiB
Java
package com.vnp.demo;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
public class BusinessException extends RuntimeException {
|
|
|
|
private final String code;
|
|
private final HttpStatus status;
|
|
|
|
public BusinessException(String code, String message, HttpStatus status) {
|
|
super(message);
|
|
this.code = code;
|
|
this.status = status;
|
|
}
|
|
|
|
public String getCode() {
|
|
return code;
|
|
}
|
|
|
|
public HttpStatus getStatus() {
|
|
return status;
|
|
}
|
|
|
|
public static BusinessException notFound() {
|
|
return new BusinessException(
|
|
"not_found",
|
|
"Объект не найден",
|
|
HttpStatus.NOT_FOUND
|
|
);
|
|
}
|
|
|
|
public static BusinessException conflict() {
|
|
return conflict("Конфликт");
|
|
}
|
|
|
|
public static BusinessException conflict(String message) {
|
|
return new BusinessException(
|
|
"conflict",
|
|
message,
|
|
HttpStatus.CONFLICT
|
|
);
|
|
}
|
|
|
|
public static BusinessException unauthorized() {
|
|
return unauthorized("Пользователь не найден");
|
|
}
|
|
|
|
public static BusinessException unauthorized(String message) {
|
|
return new BusinessException(
|
|
"unauthorized",
|
|
message,
|
|
HttpStatus.UNAUTHORIZED
|
|
);
|
|
}
|
|
|
|
public static BusinessException invalid(String message) {
|
|
return new BusinessException(
|
|
"invalid_request",
|
|
message,
|
|
HttpStatus.BAD_REQUEST
|
|
);
|
|
}
|
|
} |