mirror of https://github.com/halo-dev/halo
Add HaloException(s)
parent
90aa7c1077
commit
df26777ddc
|
@ -0,0 +1,18 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
/**
|
||||
* Exception caused by entity existence already.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class AlreadyExistsException extends BadRequestException {
|
||||
|
||||
public AlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AlreadyExistsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Exception caused by bad request.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class BadRequestException extends HaloException {
|
||||
|
||||
public BadRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BadRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatus() {
|
||||
return HttpStatus.BAD_REQUEST;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Exception caused by accessing forbidden resources.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class ForbiddenException extends HaloException {
|
||||
|
||||
public ForbiddenException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ForbiddenException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatus() {
|
||||
return HttpStatus.FORBIDDEN;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Base exception of the project.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public abstract class HaloException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Error errorData.
|
||||
*/
|
||||
private Object errorData;
|
||||
|
||||
public HaloException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public HaloException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public abstract HttpStatus getStatus();
|
||||
|
||||
@Nullable
|
||||
public Object getErrorData() {
|
||||
return errorData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets error errorData.
|
||||
*
|
||||
* @param errorData error data
|
||||
* @return current exception.
|
||||
*/
|
||||
@NonNull
|
||||
public HaloException setErrorData(@Nullable Object errorData) {
|
||||
this.errorData = errorData;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Exception of entity not found.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class NotFoundException extends HaloException {
|
||||
|
||||
public NotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatus() {
|
||||
return HttpStatus.NOT_FOUND;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.ryanc.halo.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Exception caused by service.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
public class ServiceException extends HaloException {
|
||||
|
||||
public ServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatus() {
|
||||
return HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue