fix: separate Docker ID and URL validation error messages
This commit is contained in:
1 parent
edad05b63b
commit
0f91d3b6e1
1 file changed
+7
-2
@@ -114,6 +114,9 @@ const monitorValidation = joi.object({
|
||||
.string()
|
||||
.trim()
|
||||
.custom((value, helpers) => {
|
||||
// Get the current validation context
|
||||
const { type } = helpers.state.ancestors[0];
|
||||
|
||||
// Regex from https://gist.github.com/dperini/729294
|
||||
var urlRegex = new RegExp(
|
||||
"^" +
|
||||
@@ -152,7 +155,8 @@ const monitorValidation = joi.object({
|
||||
"i"
|
||||
);
|
||||
if (!urlRegex.test(value)) {
|
||||
return helpers.error("string.invalidUrl");
|
||||
// Use different error key based on monitor type
|
||||
return helpers.error(type === "docker" ? "string.invalidDockerID" : "string.invalidUrl");
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -161,7 +165,8 @@ const monitorValidation = joi.object({
|
||||
.messages({
|
||||
"string.empty": "This field is required.",
|
||||
"string.uri": "The URL you provided is not valid.",
|
||||
"string.invalidUrl": "Please enter a valid 64-character Docker container ID",
|
||||
"string.invalidUrl": "Please enter a valid URL.",
|
||||
"string.invalidDockerID": "Please enter a valid 64-character Docker container ID.",
|
||||
"string.pattern.base": "Please enter a valid container ID.",
|
||||
}),
|
||||
port: joi
|
||||
|
||||
Reference in new issue
Block a user