This commit is contained in:
@@ -13,6 +13,9 @@ export default {
|
|||||||
developmentModeShowErrorsImmediately(showErrorsImmediately) {
|
developmentModeShowErrorsImmediately(showErrorsImmediately) {
|
||||||
devModeShowErrors = showErrorsImmediately;
|
devModeShowErrors = showErrorsImmediately;
|
||||||
},
|
},
|
||||||
|
devMode() {
|
||||||
|
return devModeShowErrors;
|
||||||
|
},
|
||||||
handleGeneralError(message, source, lineno, colno, error) {
|
handleGeneralError(message, source, lineno, colno, error) {
|
||||||
var msg = "General error: \n" + message;
|
var msg = "General error: \n" + message;
|
||||||
if (source) {
|
if (source) {
|
||||||
|
|||||||
@@ -251,18 +251,72 @@ When the form is submitted all server errors cleared if any from previous submit
|
|||||||
//example error when submit when there are no roles set at all (blank)
|
//example error when submit when there are no roles set at all (blank)
|
||||||
//{"error":{"code":"2200","details":[{"code":"2200","message":"","target":"roles","error":"VALIDATION_FAILED"}],"message":"Object did not pass validation"}}
|
//{"error":{"code":"2200","details":[{"code":"2200","message":"","target":"roles","error":"VALIDATION_FAILED"}],"message":"Object did not pass validation"}}
|
||||||
|
|
||||||
|
Here are all the API level error codes that can be returned by the API server:
|
||||||
|
|
||||||
|
| CODE | MEANING |
|
||||||
|
| ----- | ------------------------------ |
|
||||||
|
//THESE ARE ALL GENERAL FORM LEVEL ERRORS
|
||||||
|
| 2000 | API closed - Server is running but access to the API has been closed to all users |
|
||||||
|
| 2001 | API closed all non OPS routes - Server is running but access to the API has been restricted to only server maintenance operations related functionality |
|
||||||
|
| 2002 | Internal error from the API server, details in [server log](common-log.md) file |
|
||||||
|
| 2003 | Authentication failed, bad login or password, user not found |
|
||||||
|
| 2004 | Not authorized - current user is not authorized for operation attempted on the resource (insufficient rights) |
|
||||||
|
| 2005 | Object was changed by another user since retrieval (concurrency token mismatch) |
|
||||||
|
| 2010 | Object not found - API could not find the object requested |
|
||||||
|
| 2020 | PUT Id mismatch - object Id does not match route Id |
|
||||||
|
| 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
|
||||||
|
| 2201 | Validation error - Field is required but is empty or null |
|
||||||
|
| 2202 | Validation error - Field length exceeded |
|
||||||
|
| 2203 | Validation error - invalid value |
|
||||||
|
|
||||||
|
"ErrorAPI2000":"The server is closed",
|
||||||
|
"ErrorAPI2001":"The server is closed for maintenance",
|
||||||
|
"ErrorAPI2002":"Internal server error",
|
||||||
|
"ErrorAPI2003":"Authentication failed",
|
||||||
|
"ErrorAPI2004":"Not authorized",
|
||||||
|
"ErrorAPI2005":"Object was recently changed by another user and can't be saved",
|
||||||
|
"ErrorAPI2010":"Object not found",
|
||||||
|
"ErrorAPI2020":"Route id doesn't match object id",
|
||||||
|
"ErrorAPI2030":"Invalid operation",
|
||||||
|
"ErrorAPI2200":"Validation error",
|
||||||
|
"ErrorAPI2201":"Required field",
|
||||||
|
"ErrorAPI2202":"Length exceeded",
|
||||||
|
"ErrorAPI2203":"Invalid value"
|
||||||
*/
|
*/
|
||||||
//debugger;
|
var ret = [];
|
||||||
|
|
||||||
//check for errors if we have any errors
|
//check for errors if we have any errors
|
||||||
if (!v.$_.isEmpty(v.serverErrors)) {
|
if (!v.$_.isEmpty(v.serverError)) {
|
||||||
if (ref == "roles") {
|
debugger;
|
||||||
return ["Test error from GZVALIDATE::ServerErrors"];
|
//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?
|
||||||
|
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());
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//Specific field errors
|
||||||
|
|
||||||
|
//example
|
||||||
|
if (ref == "xroles") {
|
||||||
|
return ["Test error from GZVALIDATE::ServerErrors"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//default if no error message to display
|
//default if no error message to display
|
||||||
return [];
|
return ret;
|
||||||
|
|
||||||
// var ctrl = getControl(v, ref);
|
// var ctrl = getControl(v, ref);
|
||||||
// if (typeof ctrl == "undefined") {
|
// if (typeof ctrl == "undefined") {
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ Object.defineProperty(Vue.prototype, "$gzv", { value: gzvalidate });
|
|||||||
Object.defineProperty(Vue.prototype, "$gzerror", {
|
Object.defineProperty(Vue.prototype, "$gzerror", {
|
||||||
value: errorHandler.handleFormError
|
value: errorHandler.handleFormError
|
||||||
});
|
});
|
||||||
|
Object.defineProperty(Vue.prototype, "$gzdevmode", {
|
||||||
|
value: errorHandler.devMode
|
||||||
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// FORM VALIDATION
|
// FORM VALIDATION
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<v-layout align-center justify-space-around row wrap mt-5>
|
<v-layout align-center justify-space-around row wrap mt-5>
|
||||||
<v-flex xs1>
|
<v-flex xs1>
|
||||||
<v-btn @click="validate">Force validate</v-btn>
|
<v-btn>test 1</v-btn>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
<v-flex xs1>
|
<v-flex xs1>
|
||||||
<v-btn>test2</v-btn>
|
<v-btn>test2</v-btn>
|
||||||
@@ -150,7 +150,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
obj: {},
|
obj: {},
|
||||||
serverErrors: {},
|
serverError: {},
|
||||||
formReady: false
|
formReady: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -176,12 +176,11 @@ export default {
|
|||||||
if (res.error) {
|
if (res.error) {
|
||||||
//debugger;
|
//debugger;
|
||||||
//Set errors so form can pick them up for controls in canHasServerErrors
|
//Set errors so form can pick them up for controls in canHasServerErrors
|
||||||
that.serverErrors = res.error;
|
that.serverError = res.error;
|
||||||
// that.$refs.form.resetValidation();
|
// that.$refs.form.resetValidation();
|
||||||
// that.$refs.form.validate();
|
// that.$refs.form.validate();
|
||||||
//example error when submit when there are no roles set at all (blank)
|
//example error when submit when there are no roles set at all (blank)
|
||||||
//{"error":{"code":"2200","details":[{"code":"2200","message":"","target":"roles","error":"VALIDATION_FAILED"}],"message":"Object did not pass validation"}}
|
//{"error":{"code":"2200","details":[{"code":"2200","message":"","target":"roles","error":"VALIDATION_FAILED"}],"message":"Object did not pass validation"}}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
||||||
if (res.id) {
|
if (res.id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user