This commit is contained in:
2019-03-28 19:22:57 +00:00
parent 4955552e57
commit f3925bfd64
4 changed files with 71 additions and 12 deletions

View File

@@ -13,6 +13,9 @@ export default {
developmentModeShowErrorsImmediately(showErrorsImmediately) {
devModeShowErrors = showErrorsImmediately;
},
devMode() {
return devModeShowErrors;
},
handleGeneralError(message, source, lineno, colno, error) {
var msg = "General error: \n" + message;
if (source) {

View File

@@ -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)
//{"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
if (!v.$_.isEmpty(v.serverErrors)) {
if (ref == "roles") {
return ["Test error from GZVALIDATE::ServerErrors"];
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?
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
return [];
return ret;
// var ctrl = getControl(v, ref);
// if (typeof ctrl == "undefined") {

View File

@@ -30,6 +30,9 @@ Object.defineProperty(Vue.prototype, "$gzv", { value: gzvalidate });
Object.defineProperty(Vue.prototype, "$gzerror", {
value: errorHandler.handleFormError
});
Object.defineProperty(Vue.prototype, "$gzdevmode", {
value: errorHandler.devMode
});
/////////////////////////////////////////////////////////////////
// FORM VALIDATION

View File

@@ -88,7 +88,7 @@
<v-layout align-center justify-space-around row wrap mt-5>
<v-flex xs1>
<v-btn @click="validate">Force validate</v-btn>
<v-btn>test 1</v-btn>
</v-flex>
<v-flex xs1>
<v-btn>test2</v-btn>
@@ -150,11 +150,11 @@ export default {
data() {
return {
obj: {},
serverErrors: {},
serverError: {},
formReady: false
};
},
methods: {
methods: {
getDataFromApi() {
var url = "Widget/" + this.$route.params.id;
this.$gzapi.get(url).then(res => {
@@ -175,13 +175,12 @@ export default {
.then(res => {
if (res.error) {
//debugger;
//Set errors so form can pick them up for controls in canHasServerErrors
that.serverErrors = res.error;
//Set errors so form can pick them up for controls in canHasServerErrors
that.serverError = res.error;
// that.$refs.form.resetValidation();
// that.$refs.form.validate();
//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"}}
} else {
//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) {