Skip to content

Commit

Permalink
feat:Business logic exception categorized as features
Browse files Browse the repository at this point in the history
feat:Business logic exception categorized as features
  • Loading branch information
sathish Ramesh committed Nov 12, 2024
1 parent 1edf0b8 commit 101875e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
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();
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}

0 comments on commit 101875e

Please sign in to comment.