Package io.github.pasinduog.exception
Class ApiException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.pasinduog.exception.ApiException
- All Implemented Interfaces:
Serializable
Base abstract class for all custom API exceptions in the application.
Instead of throwing generic exceptions, developers should extend this class
to create specific business exceptions. This allows the GlobalExceptionHandler
to automatically capture the specific HttpStatus and message defined by the subclass.
Example Usage:
public class ResourceNotFoundException extends ApiException {
public ResourceNotFoundException(String resource, Long id) {
super(String.format("%s not found with ID: %d", resource, id), HttpStatus.NOT_FOUND);
}
}
- Since:
- 1.2.0
- Version:
- 2.0.1
- Author:
- Pasindu OG
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedApiException(String message, org.springframework.http.HttpStatus status) Constructs a new ApiException with a detailed message and specific HTTP status. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ApiException
Constructs a new ApiException with a detailed message and specific HTTP status.- Parameters:
message- The detail message explaining the cause of the error.status- TheHttpStatusto be returned to the client.
-