Skip to content

Commit 0d0998a

Browse files
Extract a constant
1 parent 0682a30 commit 0d0998a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

model/src/main/kotlin/io/spine/validation/CompanionErrorMessage.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ import io.spine.validation.protodata.getDescriptor
4949
*/
5050
internal inline fun <reified T : Message> resolveErrorMessage(field: Field): String {
5151
val descriptor = T::class.getDescriptor()
52-
val errorMessageField = descriptor.field("error_msg")
52+
val errorMessageField = descriptor.field(CUSTOM_MESSAGE_FIELD)
5353
val customMessage = field.findOption<T>()?.getField(errorMessageField) as String?
5454
return customMessage ?: descriptor.defaultMessage
5555
}
56+
57+
/**
58+
* The name of the field that contains a custom error message.
59+
*
60+
* This field name is a convention, which all companion error message options
61+
* are expected to follow.
62+
*/
63+
private const val CUSTOM_MESSAGE_FIELD = "error_msg"

0 commit comments

Comments
 (0)