This commit is contained in:
2019-04-01 23:55:04 +00:00
parent 00cd7b8af9
commit e4837d44a4
3 changed files with 96 additions and 38 deletions

View File

@@ -328,52 +328,56 @@ Here are all the API level error codes that can be returned by the API server:
var apiErrorCode = parseInt(v.serverError.code);
//OBJECT ERROR
if (ref == "apierrors" && apiErrorCode < 2201) {
//we have a general error, format for return
// "ErrorFieldValueNotInteger": "Value must be an integer"
//TODO: This logic is faulty, there could be overall errors that are not field specific, however there are also field ones that trigger overall errors.
//Keep top part if statement for gathering all overall errors, but then also run the field errors block and check for field errors where "target" is empty and add them in to the return as well
//GENERAL ERROR
if (ref == "errorbox") {
//Add any general errors to ret
var err = v.$gzlocale.get("ErrorAPI" + apiErrorCode.toString());
if (v.serverError.message) {
err = err + "\r\n" + v.serverError.message;
}
ret = [err];
} else {
//FIELD ERROR
//{"error":{"code":"2200","details":[{"message":"Exception: Error converting value \"\" to type 'AyaNova.Biz.AuthorizationRoles'. Path 'roles', line 1, position 141.","target":"roles","error":"2203"}],"message":"Object did not pass validation"}}
//Specific field validation errors are in an array in "details" key
if (!v.$_.isEmpty(v.serverError.details)) {
//See if this key is in the details array
var errorsForField = v.$_.filter(v.serverError.details, {
ret.push(err);
}
//DETAIL ERRORS
//{"error":{"code":"2200","details":[{"message":"Exception: Error converting value \"\" to type 'AyaNova.Biz.AuthorizationRoles'. Path 'roles', line 1, position 141.","target":"roles","error":"2203"}],"message":"Object did not pass validation"}}
//Specific field validation errors are in an array in "details" key
if (!v.$_.isEmpty(v.serverError.details)) {
//See if this key is in the details array
var errorsForField = [];
if (ref == "errorbox") {
errorsForField = v.$_.filter(v.serverError.details, function(o) {
return !o.target;
});
} else {
errorsForField = v.$_.filter(v.serverError.details, {
target: ref
});
if (errorsForField.length > 0) {
var allFldErrors = "";
//iterate the errorsForField objects, build a return message for each error separated by a newline and Bob's your lobster
v.$_.each(errorsForField, function(ve) {
var fldErr = "";
var fldErrorCode = parseInt(ve.error);
fldErr =
v.$gzlocale.get("ErrorAPI" + fldErrorCode.toString()) +
" [" +
ve.error +
"]";
if (ve.message) {
fldErr += " - \"" + ve.message + "\"";
}
allFldErrors += fldErr + "\n";
});
return allFldErrors.trimRight("\n");
}
} else {
if (v.$gzdevmode()) {
throw "DEV ERROR gzvalidate::ServerErrors -> on field validation error no 'details' key was found to show which field had the error";
}
}
//example
if (ref == "xroles") {
return ["Test error from GZVALIDATE::ServerErrors"];
if (errorsForField.length > 0) {
//iterate the errorsForField object and add each to return array of errors
v.$_.each(errorsForField, function(ve) {
var fldErr = "";
var fldErrorCode = parseInt(ve.error);
fldErr =
v.$gzlocale.get("ErrorAPI" + fldErrorCode.toString()) +
" [" +
ve.error +
"]";
if (ve.message) {
fldErr += ' - "' + ve.message + '"';
}
ret.push(fldErr);
});
return ret;
}
} else {
if (v.$gzdevmode()) {
throw "DEV ERROR gzvalidate::ServerErrors -> on field validation error no 'details' key was found to show which field had the error";
}
}
}
@@ -399,5 +403,22 @@ Here are all the API level error codes that can be returned by the API server:
// var err = v.$gzlocale.get("ErrorFieldValueNotInteger");
// return err;
},
///////////////////////////////
// ERROR BOX ERRORS
// displays any messages for error box on form which is the generic catch all for non field specific errors from server
ErrorBoxErrors(v) {
var errs = this.ServerErrors(v, "errorbox");
if (errs.length < 1) {
return null;
}
var ret = "";
//loop array and append each error to a return string
for (var i = 0; i < errs.length; i++) {
ret += errs[i] + "\r\n";
}
ret=ret.replace("\r\n"," <br/> ");
return ret;
}
};