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:
- Consistency: Every service in your ecosystem reports the same failure with the same wording, giving clients a predictable experience.
- Readability:
BaseErrorMessage.EmailRequiredis self-documenting, unlike a scattered string literal. - Maintainability: If a message needs rewording, you change it in one central location.
- 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 arestatic 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,caselabels, orconstdeclarations. See the migration guide for replacements.
Values
| Field Name | Message |
|---|---|
| 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
EmailMaxLengthfield. The maximum-length message is built dynamically by theBaseErrorCode.EmailMaxLengthfor the matching error code.
IBAN note: The
IBANvalue object performs structural validation, so a malformed or wrongly sized value usesIbanNotValid.IbanLengthis 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:
responseTypeis an enum-backed field. The"BadRequest"form above appears only when aJsonStringEnumConverteris registered; with defaultSystem.Text.Jsonoptions it is written as the numeric value12. SeeResponseType.