-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:Business logic exception categorized as features
feat:Business logic exception categorized as features
- Loading branch information
sathish Ramesh
committed
Nov 12, 2024
1 parent
1edf0b8
commit 101875e
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
mdx-models/src/main/java/com/mx/path/model/mdx/accessor/feature/ErrorDescriptor.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,27 @@ | ||
package com.mx.path.model.mdx.accessor.feature; | ||
|
||
/** | ||
* ErrorDescriptor representing different error descriptors in the application. | ||
* <p> | ||
* This enum provides a centralized way to manage error descriptors used | ||
* throughout the application. Each constant represents a specific error | ||
* condition that may arise during application operations. | ||
* </p> | ||
* <p> | ||
* Usage: | ||
* <p> | ||
* Use these constants to represent error conditions when throwing | ||
* exceptions or logging errors, ensuring consistency across the application. | ||
* </p> | ||
*/ | ||
public enum ErrorDescriptor { | ||
INSUFFICIENT_FUNDS, | ||
ACCOUNT_NOT_FOUND, | ||
UNKNOWN_ERROR; | ||
// todo: All the expected ErrorDescriptors will be added here. | ||
|
||
@Override | ||
public String toString() { | ||
return name(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
mdx-models/src/main/java/com/mx/path/model/mdx/accessor/feature/FeatureException.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,37 @@ | ||
package com.mx.path.model.mdx.accessor.feature; | ||
|
||
import com.mx.path.core.common.exception.PathRequestException; | ||
import com.mx.path.core.common.request.Feature; | ||
|
||
/** | ||
* Base class for exceptions related to features in the path-mdx-model project. | ||
* <p> | ||
* This exception serves as a foundation for defining feature-specific errors. | ||
* It sets appropriate headers for responses, including the feature name and | ||
* error descriptor. | ||
* <p> | ||
* Usage: | ||
* <p> | ||
* To create a new feature-specific exception, extend this class and use the | ||
* constructor to set the user message, feature, and error descriptor. | ||
*/ | ||
public abstract class FeatureException extends PathRequestException { | ||
|
||
private final Feature feature; | ||
private final ErrorDescriptor errorDescriptor; | ||
|
||
protected FeatureException(String userMessage, Feature feature, ErrorDescriptor errorDescriptor) { | ||
super(userMessage); | ||
this.feature = feature; | ||
this.errorDescriptor = errorDescriptor; | ||
initialize(); | ||
} | ||
|
||
/** | ||
* Initializes headers for the exception. | ||
*/ | ||
private void initialize() { | ||
withHeader("MX-Feature", feature.toString().toLowerCase()); | ||
withHeader("MX-Feature-Error", errorDescriptor.toString()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mdx-models/src/main/java/com/mx/path/model/mdx/accessor/payment/PaymentException.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,25 @@ | ||
package com.mx.path.model.mdx.accessor.payment; | ||
|
||
import com.mx.path.core.common.request.Feature; | ||
import com.mx.path.model.mdx.accessor.feature.ErrorDescriptor; | ||
import com.mx.path.model.mdx.accessor.feature.FeatureException; | ||
|
||
/** | ||
* Exception thrown when there is an error related to payment. | ||
* <p> | ||
* This exception is used for payment-related errors, allowing for specific | ||
* error descriptors to be specified. | ||
* </p> | ||
*/ | ||
public class PaymentException extends FeatureException { | ||
|
||
/** | ||
* Constructs a PaymentException with a specific user message and error descriptor. | ||
* | ||
* @param userMessage The message to be displayed to the user. | ||
* @param errorDescriptor The error descriptor for this exception. | ||
*/ | ||
public PaymentException(String userMessage, ErrorDescriptor errorDescriptor) { | ||
super(userMessage, Feature.PAYMENTS, errorDescriptor); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...s/src/main/java/com/mx/path/model/mdx/accessor/remote_deposit/RemoteDepositException.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,25 @@ | ||
package com.mx.path.model.mdx.accessor.remote_deposit; | ||
|
||
import com.mx.path.core.common.request.Feature; | ||
import com.mx.path.model.mdx.accessor.feature.ErrorDescriptor; | ||
import com.mx.path.model.mdx.accessor.feature.FeatureException; | ||
|
||
/** | ||
* Exception thrown when there is an error related to remote deposit. | ||
* <p> | ||
* This exception is used for remote deposit-related errors, allowing for specific | ||
* error descriptors to be specified. | ||
* </p> | ||
*/ | ||
public class RemoteDepositException extends FeatureException { | ||
|
||
/** | ||
* Constructs a RemoteDepositException with a specific user message and error descriptor. | ||
* | ||
* @param userMessage The message to be displayed to the user. | ||
* @param errorDescriptor The error descriptor for this exception. | ||
*/ | ||
public RemoteDepositException(String userMessage, ErrorDescriptor errorDescriptor) { | ||
super(userMessage, Feature.REMOTE_DEPOSITS, errorDescriptor); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mdx-models/src/main/java/com/mx/path/model/mdx/accessor/transfer/TransferException.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,25 @@ | ||
package com.mx.path.model.mdx.accessor.transfer; | ||
|
||
import com.mx.path.core.common.request.Feature; | ||
import com.mx.path.model.mdx.accessor.feature.ErrorDescriptor; | ||
import com.mx.path.model.mdx.accessor.feature.FeatureException; | ||
|
||
/** | ||
* Exception thrown when there is an error related to transfers. | ||
* <p> | ||
* This exception is used for transfer-related errors, allowing for specific | ||
* error descriptors to be specified. | ||
* </p> | ||
*/ | ||
public class TransferException extends FeatureException { | ||
|
||
/** | ||
* Constructs a TransferException with a specific user message and error descriptor. | ||
* | ||
* @param userMessage The message to be displayed to the user. | ||
* @param errorDescriptor The error descriptor for this exception. | ||
*/ | ||
public TransferException(String userMessage, ErrorDescriptor errorDescriptor) { | ||
super(userMessage, Feature.TRANSFERS, errorDescriptor); | ||
} | ||
} |