Class ApiException

All Implemented Interfaces:
Serializable

public abstract class ApiException extends RuntimeException
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 Details

    • ApiException

      protected ApiException(String message, org.springframework.http.HttpStatus status)
      Constructs a new ApiException with a detailed message and specific HTTP status.
      Parameters:
      message - The detail message explaining the cause of the error.
      status - The HttpStatus to be returned to the client.