-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from Guhapriya01/feature/pagination-sorting-api
Improve Exception Handling for Invalid Sort Fields
- Loading branch information
Showing
5 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/libraryman_api/exception/InvalidSortFieldException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.libraryman_api.exception; | ||
|
||
import java.io.Serial; | ||
|
||
/** | ||
* Custom exception class to handle scenarios where an invalid sort field | ||
* is provided for API requests in the Library Management System. | ||
* This exception is thrown when a sorting operation is attempted | ||
* using a field that does not exist or is not supported. | ||
*/ | ||
public class InvalidSortFieldException extends RuntimeException { | ||
|
||
/** | ||
* The {@code serialVersionUID} is a unique identifier for each version of a serializable class. | ||
* It is used during the deserialization process to verify that the sender and receiver of a | ||
* serialized object have loaded classes for that object that are compatible with each other. | ||
* | ||
* The {@code serialVersionUID} field is important for ensuring that a serialized class | ||
* (especially when transmitted over a network or saved to disk) can be successfully deserialized, | ||
* even if the class definition changes in later versions. If the {@code serialVersionUID} does not | ||
* match during deserialization, an {@code InvalidClassException} is thrown. | ||
* | ||
* This field is optional, but it is good practice to explicitly declare it to prevent | ||
* automatic generation, which could lead to compatibility issues when the class structure changes. | ||
* | ||
* The {@code @Serial} annotation is used here to indicate that this field is related to | ||
* serialization. This annotation is available starting from Java 14 and helps improve clarity | ||
* regarding the purpose of this field. | ||
*/ | ||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Constructs a new {@code InvalidSortFieldException} with the specified detail message. | ||
* | ||
* @param message the detail message explaining the reason for the exception | ||
*/ | ||
public InvalidSortFieldException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new {@code InvalidSortFieldException} with the specified detail message and cause. | ||
* | ||
* @param message the detail message explaining the reason for the exception | ||
* @param cause the cause of the exception (which is saved for later retrieval by the {@link #getCause()} method) | ||
*/ | ||
public InvalidSortFieldException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters