All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.hison.api.exception.ServiceRuntimeException Maven / Gradle / Ivy

Go to download

API-Link is a novel solution for Spring projects, aimed at streamlining development by eliminating the need for individual controllers. It allows developers to use a single 'cmd' value to invoke service layer methods, simplifying workflow and boosting productivity.

The newest version!
package io.github.hison.api.exception;

/**
 * 
 * Custom exception class for handling exceptions that occur within service layer operations.
 * Extends RuntimeException and includes an additional error code for more detailed exception categorization.
 * This class is designed to be used in conjunction with the ApiHandler's handleServiceRuntimeException method,
 * allowing for customizable catch logic.
 * 
 * 

Key Features:

*
    *
  • Standard runtime exception handling with the addition of an error code.
  • *
  • Enables structured error handling in service layer operations.
  • *
  • Integrates seamlessly with ApiController, automatically redirecting to ApiHandler's handleServiceRuntimeException for error processing.
  • *
*

Usage and Integration:

*
 *     // Throwing a ServiceRuntimeException in service layer
 *     @Service
 *     public class MemberService {
 *         public DataWrapper getMember(DataWrapper dw) {
 *             throw new ServiceRuntimeException("This is Runtime exception message test", "ERR0001");
 *         }
 *         ...
 *     }
 * 
 *     // Handling in ApiHandler
 *     public ResponseEntity<DataWrapper> handleServiceRuntimeException(ServiceRuntimeException e, DataWrapper dw, HttpServletRequest req) {
 *         // Custom catch logic here
 *     }
 * 
* * ServiceRuntimeException is vital for a structured approach to handling errors in the service layer, * providing a clear path for managing exceptions and enhancing error response mechanisms in API operations. * * @author Hani son * @version 1.0.0 */ public class ServiceRuntimeException extends RuntimeException { private String code = "0000"; public ServiceRuntimeException(String message) { super(message); } public ServiceRuntimeException(String message, String code) { super(message); this.code = code; } public ServiceRuntimeException(String message, Throwable cause) { super(message, cause); } public ServiceRuntimeException(String message, Throwable cause, String code) { super(message, cause); this.code = code; } public ServiceRuntimeException(Throwable cause) { super(cause.toString(), cause); } public ServiceRuntimeException(Throwable cause, String code) { super(cause.toString(), cause); this.code = code; } public ServiceRuntimeException(ServiceRuntimeException cause) { super(cause.toString(), cause); } public ServiceRuntimeException(ServiceRuntimeException cause, String code) { super(cause.toString(), cause); this.code = code; } public String getCode() { return this.code; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy