This commit is contained in:
2019-03-28 20:33:18 +00:00
parent 66ac0b9bee
commit 1f6b9e8fe7

View File

@@ -225,7 +225,15 @@ export default {
if (v.$gzdevmode()) {
//make sure serverErrors is defined on data
if (!v$_.has(v, "serverError")) {
throw "DEV ERROR: serverError seems to be missing from form's vue data object";
throw "DEV ERROR gzvalidate::ServerErrors -> serverError seems to be missing from form's vue data object";
}
//ensure the error returned is in an expected format to catch coding errors at the server end
if (!v.$_.isEmpty(v.serverError)) {
//Make sure there is an error code if there is an error collection
if (!v.serverError.code) {
throw "DEV ERROR gzvalidate::ServerErrors -> server returned error without code";
}
}
}
//OK, this is sketchy a bit but seems to work
@@ -274,11 +282,12 @@ Here are all the API level error codes that can be returned by the API server:
| 2030 | Invalid operation - operation could not be completed, not valid, details in message property |
| 2200 | Validation error - general top level indicating object was not valid, specifics in "details" property |
//THESE HAVE FIELD NAMES IN AN ARRAY MAYBE
//THESE HAVE FIELD NAMES IN AN ARRAY under details
| 2201 | Validation error - Field is required but is empty or null |
| 2202 | Validation error - Field length exceeded |
| 2203 | Validation error - invalid value |
//general errors
"ErrorAPI2000":"The server is closed",
"ErrorAPI2001":"The server is closed for maintenance",
"ErrorAPI2002":"Internal server error",
@@ -289,6 +298,8 @@ Here are all the API level error codes that can be returned by the API server:
"ErrorAPI2020":"Route id doesn't match object id",
"ErrorAPI2030":"Invalid operation",
"ErrorAPI2200":"Validation error",
//field errors
"ErrorAPI2201":"Required field",
"ErrorAPI2202":"Length exceeded",
"ErrorAPI2203":"Invalid value"
@@ -299,18 +310,35 @@ Here are all the API level error codes that can be returned by the API server:
if (!v.$_.isEmpty(v.serverError)) {
debugger;
//First let's get the top level error code
if (!v.serverError.code) {
throw "gzvalidate::ServerErrors -> server returned error without code";
}
var apiErrorCode = parseInt(v.serverError.code);
//General form errors?
//OBJECT ERROR
if (ref == "apierrors" && apiErrorCode < 2201) {
//we have a general error, format for return
// "ErrorFieldValueNotInteger": "Value must be an integer"
var err = v.$gzlocale.get("ErrorAPI" + apiErrorCode.toString());
if (v.serverError.message) {
err = err + "\r\n" + v.serverError.message;
}
ret = [err];
} else {
//Specific field errors
//FIELD ERROR
//{"error":{"code":"2200","details":[{"code":"2200","message":"","target":"roles","error":"VALIDATION_FAILED"}],"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.$_.where(v.serverError.details, {target: ref});
if(errorsForField.length>0){
//iterate the errorsForField objects, build a return message for each error separated by a newline and Bob's your lobster
}
} 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") {