Skip to main content

BaseErrorMessage

Namespace: RA.Utilities.Core.Constants

The BaseErrorMessage class provides a collection of predefined, read-only string messages for field-level validation failures. It lives within the RA.Utilities.Core.Constants package and is designed to work alongside BaseErrorCode: the code identifies the failure programmatically, while the message explains it to humans.

While BaseResponseMessages covers whole-response messaging (e.g., "The requested resource was not found."), BaseErrorMessage describes input-level problems: a missing email address, an invalid SSN, a failed IBAN check digit, a currency mismatch, and so on.

Using these values offers the same benefits as the rest of the package:

  1. Consistency: Every service in your ecosystem reports the same failure with the same wording, giving clients a predictable experience.
  2. Readability: BaseErrorMessage.EmailRequired is self-documenting, unlike a scattered string literal.
  3. Maintainability: If a message needs rewording, you change it in one central location.
  4. Reduced Errors: Named values prevent typos in string literals that are difficult to spot.

These messages are used by the value objects in RA.Utilities.Core.ValueObjects (Email, Currency, SSN, Money, IBAN) when they throw BadRequestException with structured ValidationError entries.

Read-only, not const: Since v10.0.4 these fields are static readonly, not compile-time constants. Read them directly at runtime, but do not use them where C# requires a constant expression — attribute arguments, default parameter values, case labels, or const declarations. See the migration guide for replacements.

Values​

Field NameMessage
EmailRequired"The 'Email address' field is required."
EmailNotValid"'Email address' format is invalid."
CurrencyRequired"The 'Currency' field is required."
CurrencyLength"'Currency' must be exact 3 characters."
CurrencyMismatch"Currency mismatch"
PositiveMoney"POSITIVE_MONEY"
SsnRequired"The 'SSN' field is required."
SsnLength"'SSN' must be exact 10 characters."
SsnNotValid"'SSN' format is invalid."
IbanRequired"The 'IBAN' field is required."
IbanLength"'IBAN' length does not match the expected length for its country."
IbanNotValid"'IBAN' format is invalid."
IbanCheckDigits"'IBAN' check digits are invalid."

Note: There is no EmailMaxLength field. The maximum-length message is built dynamically by the Email value object because it interpolates the configured limit into the text (e.g., "Email address must not exceed 254 characters."). See BaseErrorCode.EmailMaxLength for the matching error code.

IBAN note: The IBAN value object performs structural validation, so a malformed or wrongly sized value uses IbanNotValid. IbanLength is the message to use when you validate a country-specific length yourself. See the IBAN troubleshooting entry.

🚀 Usage Examples​

Throw a structured validation error​

Use the message as the ValidationError description and the matching code from BaseErrorCode as its ErrorCode:

using RA.Utilities.Core.Constants;
using RA.Utilities.Core.Exceptions;

public class PaymentService
{
public void Validate(string? currency)
{
if (string.IsNullOrWhiteSpace(currency))
{
throw new BadRequestException(new ValidationError(BaseErrorMessage.CurrencyRequired)
{
PropertyName = "Currency",
ErrorCode = BaseErrorCode.CurrencyRequired
});
}

// ... proceed with the payment
}
}

Pair codes and messages in a problem-details response​

The structured error is serialized into the HTTP 400 response body, so consumers see both the code and the human-readable message:

{
"responseCode": 400,
"responseType": "BadRequest",
"responseMessage": "The request is invalid.",
"result": [
{
"propertyName": "Email",
"errorMessage": "The 'Email address' field is required.",
"errorCode": "REQUIRED_EMAIL"
}
]
}

IBAN failures can carry the offending value and, for check digits, the expected value:

{
"responseCode": 400,
"responseType": "BadRequest",
"responseMessage": "The request is invalid.",
"result": [
{
"propertyName": "IBAN",
"errorMessage": "'IBAN' check digits are invalid.",
"errorCode": "IBAN_CHECK_DIGITS",
"attemptedValue": "GB81WEST12345698765432",
"expectedValue": "82"
}
]
}

JSON note: responseType is an enum-backed field. The "BadRequest" form above appears only when a JsonStringEnumConverter is registered; with default System.Text.Json options it is written as the numeric value 12. See ResponseType.