91 lines
1.8 KiB
Java
91 lines
1.8 KiB
Java
/**
|
|
*
|
|
*/
|
|
package de.bstly.board.controller.support;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import org.springframework.core.NestedExceptionUtils;
|
|
import org.springframework.core.NestedRuntimeException;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
/**
|
|
* The Class EntityResponseStatusException.
|
|
*/
|
|
public class EntityResponseStatusException extends NestedRuntimeException {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
private final HttpStatus status;
|
|
|
|
|
|
@Nullable
|
|
private final Object body;
|
|
|
|
/**
|
|
* Instantiates a new entity response status exception.
|
|
*
|
|
* @param status the status
|
|
*/
|
|
public EntityResponseStatusException(HttpStatus status) {
|
|
this(null, status);
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new entity response status exception.
|
|
*
|
|
* @param body the body
|
|
* @param status the status
|
|
*/
|
|
public EntityResponseStatusException(@Nullable Object body, HttpStatus status) {
|
|
this(body, status, null);
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new entity response status exception.
|
|
*
|
|
* @param body the body
|
|
* @param status the status
|
|
* @param cause the cause
|
|
*/
|
|
public EntityResponseStatusException(@Nullable Object body, HttpStatus status, @Nullable Throwable cause) {
|
|
super(null, cause);
|
|
Assert.notNull(status, "HttpStatus is required");
|
|
this.status = status;
|
|
this.body = body;
|
|
}
|
|
|
|
/**
|
|
* Gets the status.
|
|
*
|
|
* @return the status
|
|
*/
|
|
public HttpStatus getStatus() {
|
|
return this.status;
|
|
}
|
|
|
|
/**
|
|
* Gets the body.
|
|
*
|
|
* @return the body
|
|
*/
|
|
@Nullable
|
|
public Object getBody() {
|
|
return this.body;
|
|
}
|
|
|
|
/*
|
|
* @see org.springframework.core.NestedRuntimeException#getMessage()
|
|
*/
|
|
@Override
|
|
public String getMessage() {
|
|
String msg = this.status + (this.body != null ? " \"" + this.body + "\"" : "");
|
|
return NestedExceptionUtils.buildMessage(msg, getCause());
|
|
}
|
|
|
|
}
|