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()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.custom((value, helpers) => {
|
.custom((value, helpers) => {
|
||||||
|
// Get the current validation context
|
||||||
|
const { type } = helpers.state.ancestors[0];
|
||||||
|
|
||||||
// Regex from https://gist.github.com/dperini/729294
|
// Regex from https://gist.github.com/dperini/729294
|
||||||
var urlRegex = new RegExp(
|
var urlRegex = new RegExp(
|
||||||
"^" +
|
"^" +
|
||||||
@@ -152,7 +155,8 @@ const monitorValidation = joi.object({
|
|||||||
"i"
|
"i"
|
||||||
);
|
);
|
||||||
if (!urlRegex.test(value)) {
|
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;
|
return value;
|
||||||
@@ -161,7 +165,8 @@ const monitorValidation = joi.object({
|
|||||||
.messages({
|
.messages({
|
||||||
"string.empty": "This field is required.",
|
"string.empty": "This field is required.",
|
||||||
"string.uri": "The URL you provided is not valid.",
|
"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.",
|
"string.pattern.base": "Please enter a valid container ID.",
|
||||||
}),
|
}),
|
||||||
port: joi
|
port: joi
|
||||||
|
|||||||
Reference in new issue
Block a user