From 456bb0baddacfd75ef4b94c82e2be6d7bb5d14b8 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 28 Mar 2019 22:04:25 +0000 Subject: [PATCH] --- docs/8.0/ayanova/docs/api-error-codes.md | 2 +- .../ApiErrorCodeStockMessage.cs | 54 +++++++++++++++---- server/AyaNova/biz/ApiErrorCode.cs | 28 +++++++++- server/AyaNova/biz/ValidationError.cs | 2 +- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/docs/8.0/ayanova/docs/api-error-codes.md b/docs/8.0/ayanova/docs/api-error-codes.md index f25d6898..b842b457 100644 --- a/docs/8.0/ayanova/docs/api-error-codes.md +++ b/docs/8.0/ayanova/docs/api-error-codes.md @@ -26,6 +26,6 @@ Here are all the API level error codes that can be returned by the API server: | 2204 | Validation error - Customized form property set to required has an empty value | | 2205 | Validation error - Required property is missing entirely. Usually a development or communications error | | 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database | -| 2207 | Validation error - When an object requires a start and end date the start date must be earlier than the end date | +| 2207 | Validation error - The start date must be earlier than the end date | | 2208 | Validation error - Modifying the object (usually a delete) would break the link to other records in the database and operation was disallowed to preserve data integrity | | 2209 | Validation error - Indicates the attempted property change is invalid because the value is fixed and cannot be changed | \ No newline at end of file diff --git a/server/AyaNova/ControllerHelpers/ApiErrorCodeStockMessage.cs b/server/AyaNova/ControllerHelpers/ApiErrorCodeStockMessage.cs index 4a500782..2c4b9c68 100644 --- a/server/AyaNova/ControllerHelpers/ApiErrorCodeStockMessage.cs +++ b/server/AyaNova/ControllerHelpers/ApiErrorCodeStockMessage.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging; using AyaNova.Models; using System.Linq; using System.Collections.Generic; +using AyaNova.Biz; namespace AyaNova.Api.ControllerHelpers @@ -19,10 +20,20 @@ namespace AyaNova.Api.ControllerHelpers return "API Closed"; case ApiErrorCode.API_OPS_ONLY: return "API Closed to non operations routes"; + case ApiErrorCode.API_SERVER_ERROR: + return "Server internal error, details in server log file"; + case ApiErrorCode.AUTHENTICATION_FAILED: + return "Authentication failed"; + case ApiErrorCode.NOT_AUTHORIZED: + return "User not authorized for this resource operation (insufficient rights)"; case ApiErrorCode.CONCURRENCY_CONFLICT: return "Object was changed by another user since retrieval (concurrency token mismatch)"; case ApiErrorCode.NOT_FOUND: return "Object not found"; + case ApiErrorCode.PUT_ID_MISMATCH: + return "Update failed: ID mismatch - route ID doesn't match object id"; + case ApiErrorCode.INVALID_OPERATION: + return "An attempt was made to perform an invalid operation"; case ApiErrorCode.VALIDATION_FAILED: return "Object did not pass validation"; case ApiErrorCode.VALIDATION_REQUIRED: @@ -31,14 +42,21 @@ namespace AyaNova.Api.ControllerHelpers return "Field too long"; case ApiErrorCode.VALIDATION_INVALID_VALUE: return "Field is set to a non allowed value"; - case ApiErrorCode.AUTHENTICATION_FAILED: - return "Authentication failed"; - case ApiErrorCode.PUT_ID_MISMATCH: - return "Update failed: ID mismatch - route ID doesn't match object id"; - case ApiErrorCode.INVALID_OPERATION: - return "An attempt was made to perform an invalid operation"; - case ApiErrorCode.NOT_AUTHORIZED: - return "User not authorized for this resource operation (insufficient rights)"; + case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY: + return "Customized form property set to required has an empty value"; + case ApiErrorCode.VALIDATION_MISSING_PROPERTY: + return "Required property is missing entirel"; + case ApiErrorCode.VALIDATION_NOT_UNIQUE: + return "Field is required to be unique but an existing record with an identical value was found in the database"; + case ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE: + return "The start date must be earlier than the end date"; + case ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY: + return "Modifying the object (usually a delete) would break the link to other records in the database and operation was disallowed to preserve data integrity"; + case ApiErrorCode.VALIDATION_NOT_CHANGEABLE: + return "the value is fixed and cannot be changed"; + + + default: return null; @@ -46,10 +64,26 @@ namespace AyaNova.Api.ControllerHelpers } } /* - VALIDATION_FAILED = 2200, + API_CLOSED = 2000, + API_OPS_ONLY = 2001, + API_SERVER_ERROR = 2002, + AUTHENTICATION_FAILED = 2003, + NOT_AUTHORIZED = 2004, + CONCURRENCY_CONFLICT=2005, + NOT_FOUND = 2010, + PUT_ID_MISMATCH = 2020, + INVALID_OPERATION = 2030, + VALIDATION_FAILED = 2200, VALIDATION_REQUIRED = 2201, VALIDATION_LENGTH_EXCEEDED = 2202, - VALIDATION_INVALID_VALUE = 2203 + VALIDATION_INVALID_VALUE = 2203, + + VALIDATION_CUSTOM_REQUIRED_EMPTY = 2204, + VALIDATION_MISSING_PROPERTY = 2205, + VALIDATION_NOT_UNIQUE = 2206, + VALIDATION_STARTDATE_AFTER_ENDDATE = 2207, + VALIDATION_REFERENTIAL_INTEGRITY = 2208, + VALIDATION_NOT_CHANGEABLE = 2209 */ } diff --git a/server/AyaNova/biz/ApiErrorCode.cs b/server/AyaNova/biz/ApiErrorCode.cs index 144c373d..5e988a3e 100644 --- a/server/AyaNova/biz/ApiErrorCode.cs +++ b/server/AyaNova/biz/ApiErrorCode.cs @@ -28,8 +28,34 @@ namespace AyaNova.Biz VALIDATION_FAILED = 2200, VALIDATION_REQUIRED = 2201, VALIDATION_LENGTH_EXCEEDED = 2202, - VALIDATION_INVALID_VALUE = 2203 + VALIDATION_INVALID_VALUE = 2203, + VALIDATION_CUSTOM_REQUIRED_EMPTY = 2204, + VALIDATION_MISSING_PROPERTY = 2205, + VALIDATION_NOT_UNIQUE = 2206, + VALIDATION_STARTDATE_AFTER_ENDDATE = 2207, + VALIDATION_REFERENTIAL_INTEGRITY = 2208, + VALIDATION_NOT_CHANGEABLE = 2209 +/* +| 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). A record was attempted to be saved but another user has just modified it so it's invalid. (first save "wins") | +| 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 issue with object overall not valid, specifics in "details" property | +| 2201 | Validation error - Field is required but is empty or null | +| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error | +| 2203 | Validation error - invalid value. Usually an type mismatch or a logical or business rule mismatch (i.e. only certain values are valid for current state of object) | +| 2204 | Validation error - Customized form property set to required has an empty value | +| 2205 | Validation error - Required property is missing entirely. Usually a development or communications error | +| 2206 | Validation error - A text property is required to be unique but an existing record with an identical value was found in the database | +| 2207 | Validation error - When an object requires a start and end date the start date must be earlier than the end date | +| 2208 | Validation error - Modifying the object (usually a delete) would break the link to other records in the database and operation was disallowed to preserve data integrity | +| 2209 | Validation error - Indicates the attempted property change is invalid because the value is fixed and cannot be changed | */ } diff --git a/server/AyaNova/biz/ValidationError.cs b/server/AyaNova/biz/ValidationError.cs index bdae1154..6b34e1e0 100644 --- a/server/AyaNova/biz/ValidationError.cs +++ b/server/AyaNova/biz/ValidationError.cs @@ -3,7 +3,7 @@ namespace AyaNova.Biz public class ValidationError { - public ValidationErrorType ErrorType { get; set; } + public ApiErrorCode Code { get; set; } public string Target { get; set; } public string Message { get; set; }