Handling Exceptions in SOKit
In SOKit, exceptions are used to enforce business rules and stop the execution of an operation when invalid conditions are detected.
Exceptions can occur during several phases such as validation events, when specific fields (e.g., remark, vatNumber, etc.) do not meet requirements.
In this case we implement the following four exceptions:
EmptyRemarkException.java
package com.dev.registration.company.flow.exceptions;
import lombok.Builder;
import com.strategyobject.sokit.extensions.core.exceptions.SOKitException;
public class EmptyRemarkException extends SOKitException {
@Builder
public EmptyRemarkException() {
super(
400,
"CRS",
EmptyRemarkException.class,
"The remark field is required",
"The remark field is required.");
}
}
This exception will interrupt the operation and return a structured error response tied to the "remark" field.
Other exceptions are:
EmptyVatNumberException.java
package com.dev.registration.company.flow.exceptions;
import lombok.Builder;
import com.strategyobject.sokit.extensions.core.exceptions.SOKitException;
public class EmptyVatNumberException extends SOKitException {
@Builder
public EmptyVatNumberException() {
super(
400,
"CRS",
EmptyVatNumberException.class,
"The VAT number is required",
"The VAT number is required.");
}
}
package com.dev.registration.company.flow.exceptions;
import lombok.Builder;
import com.strategyobject.sokit.extensions.core.exceptions.SOKitException;
public class ExceedPercentageException extends SOKitException {
@Builder
public ExceedPercentageException() {
super(
400,
"CRS",
ExceedPercentageException.class,
"The total percentage is greater than 100%",
"The total percentage is greater than 100%.");
}
}
NotEmptyVatNumberException.java
package com.dev.registration.company.flow.exceptions;
import lombok.Builder;
import com.strategyobject.sokit.extensions.core.exceptions.SOKitException;
public class NotEmptyVatNumberException extends SOKitException {
@Builder
public NotEmptyVatNumberException() {
super(
400,
"CRS",
NotEmptyVatNumberException.class,
"The VAT number is not required",
"The VAT number is not required.");
}
}