diff --git a/server/AyaNova/ControllerHelpers/ApiErrorResponse.cs b/server/AyaNova/ControllerHelpers/ApiErrorResponse.cs index 42c6ff4c..7523118d 100644 --- a/server/AyaNova/ControllerHelpers/ApiErrorResponse.cs +++ b/server/AyaNova/ControllerHelpers/ApiErrorResponse.cs @@ -30,7 +30,7 @@ namespace AyaNova.Api.ControllerHelpers //try to get a stock message if nothing specified if (message == null) { - message = ApiErrorCodeStockMessage.GetMessage(apiCode); + message = ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(apiCode); } Error = new ApiError(apiCode, message, target); @@ -52,7 +52,7 @@ namespace AyaNova.Api.ControllerHelpers //Set outer error and then put validation in details - Error = new ApiError(ApiErrorCode.VALIDATION_FAILED, ApiErrorCodeStockMessage.GetMessage(ApiErrorCode.VALIDATION_FAILED)); + Error = new ApiError(ApiErrorCode.VALIDATION_FAILED, ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(ApiErrorCode.VALIDATION_FAILED)); //https://www.jerriepelser.com/blog/validation-response-aspnet-core-webapi/ @@ -88,7 +88,7 @@ namespace AyaNova.Api.ControllerHelpers //Business rule validation error response public ApiErrorResponse(List errors) { - Error = new ApiError(ApiErrorCode.VALIDATION_FAILED, ApiErrorCodeStockMessage.GetMessage(ApiErrorCode.VALIDATION_FAILED)); + Error = new ApiError(ApiErrorCode.VALIDATION_FAILED, ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(ApiErrorCode.VALIDATION_FAILED)); Error.Details = new List(); foreach (ValidationError v in errors) { diff --git a/server/AyaNova/ControllerHelpers/ApiNotAuthorizedResponse.cs b/server/AyaNova/ControllerHelpers/ApiNotAuthorizedResponse.cs index 4ce3615f..b82e07e0 100644 --- a/server/AyaNova/ControllerHelpers/ApiNotAuthorizedResponse.cs +++ b/server/AyaNova/ControllerHelpers/ApiNotAuthorizedResponse.cs @@ -23,7 +23,7 @@ namespace AyaNova.Api.ControllerHelpers //Generic error public ApiNotAuthorizedResponse() { - Error = new ApiError(ApiErrorCode.NOT_AUTHORIZED, ApiErrorCodeStockMessage.GetMessage(ApiErrorCode.NOT_AUTHORIZED)); + Error = new ApiError(ApiErrorCode.NOT_AUTHORIZED, ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(ApiErrorCode.NOT_AUTHORIZED)); log.LogDebug("ApiErrorCode={0}, message={1}", (int)ApiErrorCode.NOT_AUTHORIZED, Error.Message); } diff --git a/server/AyaNova/biz/ApiErrorCodeStockMessage.cs b/server/AyaNova/biz/ApiErrorCodeStockMessage.cs index 5d420119..7b4066a8 100644 --- a/server/AyaNova/biz/ApiErrorCodeStockMessage.cs +++ b/server/AyaNova/biz/ApiErrorCodeStockMessage.cs @@ -12,58 +12,59 @@ namespace AyaNova.Biz internal static class ApiErrorCodeStockMessage { - internal static string GetMessage(ApiErrorCode code) + internal static string GetTranslationCodeForApiErrorCode(ApiErrorCode code) { - switch (code) - { - case ApiErrorCode.API_CLOSED: - 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: - return "Required field empty"; - case ApiErrorCode.VALIDATION_LENGTH_EXCEEDED: - return "Field too long"; - case ApiErrorCode.VALIDATION_INVALID_VALUE: - return "Field is set to a non allowed value"; - case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY: - return "Customized form property is set to required but 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"; - case ApiErrorCode.CHILD_OBJECT_ERROR: - return "Errors in child object during operation"; + return $"ErrorAPI"+((int)code).ToString(); + // switch (code) + // { + // case ApiErrorCode.API_CLOSED: + // 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: + // return "Required field empty"; + // case ApiErrorCode.VALIDATION_LENGTH_EXCEEDED: + // return "Field too long"; + // case ApiErrorCode.VALIDATION_INVALID_VALUE: + // return "Field is set to a non allowed value"; + // case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY: + // return "Customized form property is set to required but 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"; + // case ApiErrorCode.CHILD_OBJECT_ERROR: + // return "Errors in child object during operation"; - default: - return null; + // default: + // return null; - } + // } } /* API_CLOSED = 2000, diff --git a/server/AyaNova/biz/BizObject.cs b/server/AyaNova/biz/BizObject.cs index 1d33a929..404abc4e 100644 --- a/server/AyaNova/biz/BizObject.cs +++ b/server/AyaNova/biz/BizObject.cs @@ -73,16 +73,15 @@ namespace AyaNova.Biz if (!HasErrors) return string.Empty; StringBuilder sb = new StringBuilder(); - sb.AppendLine("Validation errors:"); + sb.AppendLine("LT:Errors"); foreach (ValidationError e in _errors) { - var msg = e.Message; - if (string.IsNullOrWhiteSpace(msg)) - { - //msg = e.ErrorType.ToString(); - msg = ApiErrorCodeStockMessage.GetMessage(e.Code); - } - sb.AppendLine($"Target: {e.Target} error: {msg}"); + var msg = $"LT:{ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(e.Code)}"; + if(!string.IsNullOrWhiteSpace(e.Message)) + msg+=$" ,{e.Message}"; + if(!string.IsNullOrWhiteSpace(e.Target) && e.Target!="errorbox") + msg+=$" ,field: {e.Target}"; + sb.AppendLine(msg); } return sb.ToString(); } diff --git a/server/AyaNova/resource/de.json b/server/AyaNova/resource/de.json index dfbe2ed7..8e830078 100644 --- a/server/AyaNova/resource/de.json +++ b/server/AyaNova/resource/de.json @@ -1959,5 +1959,6 @@ "SendPasswordResetCode": "E-Mail zum Zurücksetzen des Passworts senden", "CopyToClipboard": "In die Zwischenablage kopieren", "VendorPopUpNotes": "Popup-Notizen", - "EraseMultipleObjectsWarning": "Warnung: Sie sind dabei, mehrere Objekte dauerhaft zu löschen.\nBist du sicher?" + "EraseMultipleObjectsWarning": "Warnung: Sie sind dabei, mehrere Objekte dauerhaft zu löschen.\nBist du sicher?", + "Errors":"Fehler" } \ No newline at end of file diff --git a/server/AyaNova/resource/en.json b/server/AyaNova/resource/en.json index 7300d2ec..fab90993 100644 --- a/server/AyaNova/resource/en.json +++ b/server/AyaNova/resource/en.json @@ -1959,5 +1959,6 @@ "SendPasswordResetCode": "Send password reset email", "CopyToClipboard": "Copy to clipboard", "VendorPopUpNotes": "Pop-up notes", - "EraseMultipleObjectsWarning": "Warning: you are about to permanently erase multiple objects.\r\nAre you sure?" + "EraseMultipleObjectsWarning": "Warning: you are about to permanently erase multiple objects.\r\nAre you sure?", + "Errors":"Errors" } \ No newline at end of file diff --git a/server/AyaNova/resource/es.json b/server/AyaNova/resource/es.json index a3da32d9..ee864bca 100644 --- a/server/AyaNova/resource/es.json +++ b/server/AyaNova/resource/es.json @@ -1959,5 +1959,6 @@ "SendPasswordResetCode": "Enviar correo electrónico de restablecimiento de contraseña", "CopyToClipboard": "Copiar al Portapapeles", "VendorPopUpNotes": "Notas emergentes", - "EraseMultipleObjectsWarning": "Advertencia: está a punto de borrar de forma permanente varios objetos.\n¿Estás seguro?" + "EraseMultipleObjectsWarning": "Advertencia: está a punto de borrar de forma permanente varios objetos.\n¿Estás seguro?", + "Errors":"Errores" } \ No newline at end of file diff --git a/server/AyaNova/resource/fr.json b/server/AyaNova/resource/fr.json index cc6731f2..af17dc2d 100644 --- a/server/AyaNova/resource/fr.json +++ b/server/AyaNova/resource/fr.json @@ -1959,5 +1959,6 @@ "SendPasswordResetCode": "Envoyer un e-mail de réinitialisation du mot de passe", "CopyToClipboard": "Copier dans le Presse-papiers", "VendorPopUpNotes": "Notes contextuelles", - "EraseMultipleObjectsWarning": "Attention: vous êtes sur le point d'effacer définitivement plusieurs objets.\nÊtes-vous sûr?" + "EraseMultipleObjectsWarning": "Attention: vous êtes sur le point d'effacer définitivement plusieurs objets.\nÊtes-vous sûr?", + "Errors":"les erreurs" } \ No newline at end of file