
io.github.cdimascio.japierrors.ApiError Maven / Gradle / Ivy
package io.github.cdimascio.japierrors;
@SuppressWarnings("unchecked")
public abstract class ApiError extends Exception {
private static IApiErrorCreator error = ApiErrorCreator.BASIC;
public static void creator(IApiErrorCreator creator) {
error = creator;
}
private static IApiErrorCreator getCreator() {
return error;
}
/**
* Create a bad request api error using the specified throwable
* @param t The exceptioo or throwable
* @return The api error
*/
public static T badRequest(Throwable t) {
return (T) error.create(HttpStatus.BAD_REQUEST, t);
}
/**
* Creates a bad request api error with the specified message
* @param message The message
* @return The api error
*/
public static T badRequest(String message) {
return (T) error.create(HttpStatus.BAD_REQUEST, message);
}
/**
* Creates a bad request api error
* @return The api error
*/
public static T badRequest() {
return (T) error.create(HttpStatus.BAD_REQUEST, "bad request");
}
/**
* Creates a conflict api error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T conflict(Throwable t) {
return (T) error.create(HttpStatus.CONFLICT, t);
}
/**
* Creates a conflict api error with the specified message
* @param message The message
* @return The api error
*/
public static T conflict(String message) {
return (T) error.create(HttpStatus.CONFLICT, message);
}
/**
* Creates a conflict error
* @return The api error
*/
public static T conflict() {
return (T) error.create(HttpStatus.CONFLICT, "conflict");
}
/**
* Create a forbidden error using the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T forbidden(Throwable t) {
return (T) error.create(HttpStatus.FORBIDDEN, t);
}
/**
* Creates a forbidden error with the specified message
* @param message The message
* @return The api error
*/
public static T forbidden(String message) {
return (T) error.create(HttpStatus.FORBIDDEN, message);
}
/**
* Creates a forbidden error
* @return The api error
*/
public static T forbidden() {
return (T) error.create(HttpStatus.FORBIDDEN, "forbidden");
}
/**
* Create a gateway timeout error using the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T gatewayTimeout(Throwable t) {
return (T) error.create(HttpStatus.GATEWAY_TIMEOUT, t);
}
/**
* Creates a gateway timeout error with the specified message
* @param message The message
* @return The api error
*/
public static T gatewayTimeout(String message) {
return (T) error.create(HttpStatus.GATEWAY_TIMEOUT, message);
}
/**
* Creates a gateway timeout error
* @return The api error
*/
public static T gatewayTimeout() {
return (T) error.create(HttpStatus.GATEWAY_TIMEOUT, "gateway timeout");
}
/**
* Create a gone error using the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T gone(Throwable t) {
return (T) error.create(HttpStatus.GONE, t);
}
/**
* Creates a gone error with the specified message
* @param message The message
* @return The api error
*/
public static T gone(String message) {
return (T) error.create(HttpStatus.GONE, message);
}
/**
* Creates a gone error
* @return The api error
*/
public static T gone() {
return (T) error.create(HttpStatus.GONE, "gone");
}
/**
* Creates an internal server error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T internalServerError(Throwable t) {
return (T) error.create(HttpStatus.INTERNAL_SERVER_ERROR, t);
}
/**
* Creates an internal server error with the specified message
* @param message The message
* @return The api error
*/
public static T internalServerError(String message) {
return (T) error.create(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
/**
* Creates an internal server error
* @return The api error
*/
public static T internalServerError() {
return (T) error.create(HttpStatus.INTERNAL_SERVER_ERROR, "internal server error");
}
/**
* Creates a not acceptable error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T notAcceptable(Throwable t) {
return (T) error.create(HttpStatus.NOT_ACCEPTABLE, t);
}
/**
* Creates a not acceptable error with the specified message
* @param message The message
* @return The api error
*/
public static T notAcceptable(String message) {
return (T) error.create(HttpStatus.NOT_ACCEPTABLE, message);
}
/**
* Creates a not acceptable error
* @return The api error
*/
public static T notAcceptable() {
return (T) error.create(HttpStatus.NOT_ACCEPTABLE, "not found");
}
/**
* Creates a not found error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T notFound(Throwable t) {
return (T) error.create(HttpStatus.NOT_FOUND, t);
}
/**
* Creates a not found error with the specified message
* @param message The message
* @return The api error
*/
public static T notFound(String message) {
return (T) error.create(HttpStatus.NOT_FOUND, message);
}
/**
* Creates a not found error
* @return The api error
*/
public static T notFound() {
return (T) error.create(HttpStatus.NOT_FOUND, "not found");
}
/**
* Creates a not implemented error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T notImplemented(Throwable t) {
return (T) error.create(HttpStatus.NOT_IMPLEMENTED, t);
}
/**
* Creates a not implemented error with the specified message
* @param message The message
* @return The api error
*/
public static T notImplemented(String message) {
return (T) error.create(HttpStatus.NOT_IMPLEMENTED, message);
}
/**
* Creates a not implemented error
* @return The api error
*/
public static T notImplemented() {
return (T) error.create(HttpStatus.NOT_IMPLEMENTED, "not implemented");
}
/**
* Creates a precondition failed error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T preconditionFailed(Throwable t) {
return (T) error.create(HttpStatus.PRECONDITION_FAILED, t);
}
/**
* Creates a precondition failed error with the specified message
* @param message The message
* @return The api error
*/
public static T preconditionFailed(String message) {
return (T) error.create(HttpStatus.PRECONDITION_FAILED, message);
}
/**
* Creates a precondition failed error
* @return The api error
*/
public static T preconditionFailed() {
return (T) error.create(HttpStatus.PRECONDITION_FAILED, "precondition failed");
}
/**
* Creates a precondition required error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T preconditionRequired(Throwable t) {
return (T) error.create(HttpStatus.PRECONDITION_REQUIRED, t);
}
/**
* Creates a precondition required error with the specified message
* @param message The message
* @return The api error
*/
public static T preconditionRequired(String message) {
return (T) error.create(HttpStatus.PRECONDITION_REQUIRED, message);
}
/**
* Creates a precondition required error
* @return The api error
*/
public static T preconditionRequired() {
return (T) error.create(HttpStatus.PRECONDITION_REQUIRED, "precondition required");
}
/**
* Creates a proxy authentication required error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T proxyAuthenticationRequired(Throwable t) {
return (T) error.create(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, t);
}
/**
* Creates a proxy authentication required error with the specified message
* @param message The message
* @return The api error
*/
public static T proxyAuthenticationRequired(String message) {
return (T) error.create(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, message);
}
/**
* Creates a proxy authentication required error
* @return The api error
*/
public static T proxyAuthenticationRequired() {
return (T) error.create(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, "proxy authentication required");
}
/**
* Creates a request entity too large error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T requestEntityTooLarge(Throwable t) {
return (T) error.create(HttpStatus.REQUEST_ENTITY_TOO_LARGE, t);
}
/**
* Creates a request entity too large error with the specified message
* @param message The message
* @return The api error
*/
public static T requestEntityTooLarge(String message) {
return (T) error.create(HttpStatus.REQUEST_ENTITY_TOO_LARGE, message);
}
/**
* Creates a request entity too large error
* @return The api error
*/
public static T requestEntityTooLarge() {
return (T) error.create(HttpStatus.NOT_IMPLEMENTED, "not implemented");
}
/**
* Creates a service unavailable error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T serviceUnavailable(Throwable t) {
return (T) error.create(HttpStatus.SERVICE_UNAVAILABLE, t);
}
/**
* Creates a service unavailable error with the specified message
* @param message The message
* @return The api error
*/
public static T serviceUnavailable(String message) {
return (T) error.create(HttpStatus.SERVICE_UNAVAILABLE, message);
}
/**
* Creates a service unavailable error
* @return The api error
*/
public static T serviceUnavailable() {
return (T) error.create(HttpStatus.SERVICE_UNAVAILABLE, "service unavailable");
}
/**
* Creates a too many requests error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T tooManyRequests(Throwable t) {
return (T) error.create(HttpStatus.TOO_MANY_REQUESTS, t);
}
/**
* Creates a too many requests error with the specified message
* @param message The message
* @return The api error
*/
public static T tooManyRequests(String message) {
return (T) error.create(HttpStatus.TOO_MANY_REQUESTS, message);
}
/**
* Creates a too many requests error
* @return The api error
*/
public static T tooManyRequests() {
return (T) error.create(HttpStatus.TOO_MANY_REQUESTS, "too many requests");
}
/**
* Creates an unauthorized error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T unauthorized(Throwable t) {
return (T) error.create(HttpStatus.UNAUTHORIZED, t);
}
/**
* Creates an unauthorized error with the specified message
* @param message The message
* @return The api error
*/
public static T unauthorized(String message) {
return (T) error.create(HttpStatus.UNAUTHORIZED, message);
}
/**
* Creates an unauthorized error
* @return The api error
*/
public static T unauthorized() {
return (T) error.create(HttpStatus.UNAUTHORIZED, "unauthorized");
}
/**
* Creates an unavailable for legal reasons error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T unavailableForLegalReasons(Throwable t) {
return (T) error.create(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, t);
}
/**
* Creates an unavailable for legal reasons error with the specified message
* @param message The message
* @return The api error
*/
public static T unavailableForLegalReasons(String message) {
return (T) error.create(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, message);
}
/**
* Creates an unavailable for legal reasons error
* @return The api error
*/
public static T unavailableForLegalReasons() {
return (T) error.create(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, "unavailable for legal reasons");
}
/**
* Creates an unsupported media type error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T unsupportedMediaType(Throwable t) {
return (T) error.create(HttpStatus.UNSUPPORTED_MEDIA_TYPE, t);
}
/**
* Creates an unsupported media type error with the specified message
* @param message The message
* @return The api error
*/
public static T unsupportedMediaType(String message) {
return (T) error.create(HttpStatus.UNSUPPORTED_MEDIA_TYPE, message);
}
/**
* Creates an unsupported media type error
* @return The api error
*/
public static T unsupportedMediaType() {
return (T) error.create(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "unsupported media type");
}
/**
* Creates an upgrade required error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T upgradeRequired(Throwable t) {
return (T) error.create(HttpStatus.UPGRADE_REQUIRED, t);
}
/**
* Creates an upgrade required error with the specified message
* @param message The message
* @return The api error
*/
public static T upgradeRequired(String message) {
return (T) error.create(HttpStatus.UPGRADE_REQUIRED, message);
}
/**
* Creates an upgrade required error
* @return The api error
*/
public static T upgradeRequired() {
return (T) error.create(HttpStatus.UPGRADE_REQUIRED, "upgrade required");
}
/**
* Creates an upgrade required error with the specified exception or throwable
* @param t The exception or throwable
* @return The api error
*/
public static T error(int code, Throwable t) {
return (T) error.create(HttpStatus.fromCode(code), t);
}
/**
* Creates an upgrade required error with the specified message
* @param message The message
* @return The api error
*/
public static T error(int code, String message) {
return (T) error.create(HttpStatus.fromCode(code), message);
}
/**
* Creates an upgrade required error
* @return The api error
*/
public static T error(int code) {
return (T) error.create(HttpStatus.fromCode(code), "error");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy