This commit is contained in:
2020-12-09 20:11:12 +00:00
parent 59f825bb36
commit fca43b0f61
8 changed files with 66 additions and 62 deletions

View File

@@ -30,7 +30,7 @@ namespace AyaNova.Api.ControllerHelpers
//try to get a stock message if nothing specified //try to get a stock message if nothing specified
if (message == null) if (message == null)
{ {
message = ApiErrorCodeStockMessage.GetMessage(apiCode); message = ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(apiCode);
} }
Error = new ApiError(apiCode, message, target); Error = new ApiError(apiCode, message, target);
@@ -52,7 +52,7 @@ namespace AyaNova.Api.ControllerHelpers
//Set outer error and then put validation in details //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/ //https://www.jerriepelser.com/blog/validation-response-aspnet-core-webapi/
@@ -88,7 +88,7 @@ namespace AyaNova.Api.ControllerHelpers
//Business rule validation error response //Business rule validation error response
public ApiErrorResponse(List<ValidationError> errors) public ApiErrorResponse(List<ValidationError> 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<ApiDetailError>(); Error.Details = new List<ApiDetailError>();
foreach (ValidationError v in errors) foreach (ValidationError v in errors)
{ {

View File

@@ -23,7 +23,7 @@ namespace AyaNova.Api.ControllerHelpers
//Generic error //Generic error
public ApiNotAuthorizedResponse() 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); log.LogDebug("ApiErrorCode={0}, message={1}", (int)ApiErrorCode.NOT_AUTHORIZED, Error.Message);
} }

View File

@@ -12,58 +12,59 @@ namespace AyaNova.Biz
internal static class ApiErrorCodeStockMessage internal static class ApiErrorCodeStockMessage
{ {
internal static string GetMessage(ApiErrorCode code) internal static string GetTranslationCodeForApiErrorCode(ApiErrorCode code)
{ {
switch (code) return $"ErrorAPI"+((int)code).ToString();
{ // switch (code)
case ApiErrorCode.API_CLOSED: // {
return "API Closed"; // case ApiErrorCode.API_CLOSED:
case ApiErrorCode.API_OPS_ONLY: // return "API Closed";
return "API Closed to non operations routes"; // case ApiErrorCode.API_OPS_ONLY:
case ApiErrorCode.API_SERVER_ERROR: // return "API Closed to non operations routes";
return "Server internal error, details in server log file"; // case ApiErrorCode.API_SERVER_ERROR:
case ApiErrorCode.AUTHENTICATION_FAILED: // return "Server internal error, details in server log file";
return "Authentication failed"; // case ApiErrorCode.AUTHENTICATION_FAILED:
case ApiErrorCode.NOT_AUTHORIZED: // return "Authentication failed";
return "User not authorized for this resource operation (insufficient rights)"; // case ApiErrorCode.NOT_AUTHORIZED:
case ApiErrorCode.CONCURRENCY_CONFLICT: // return "User not authorized for this resource operation (insufficient rights)";
return "Object was changed by another user since retrieval (concurrency token mismatch)"; // case ApiErrorCode.CONCURRENCY_CONFLICT:
case ApiErrorCode.NOT_FOUND: // return "Object was changed by another user since retrieval (concurrency token mismatch)";
return "Object not found"; // case ApiErrorCode.NOT_FOUND:
case ApiErrorCode.PUT_ID_MISMATCH: // return "Object not found";
return "Update failed: ID mismatch - route ID doesn't match object id"; // case ApiErrorCode.PUT_ID_MISMATCH:
case ApiErrorCode.INVALID_OPERATION: // return "Update failed: ID mismatch - route ID doesn't match object id";
return "An attempt was made to perform an invalid operation"; // case ApiErrorCode.INVALID_OPERATION:
case ApiErrorCode.VALIDATION_FAILED: // return "An attempt was made to perform an invalid operation";
return "Object did not pass validation"; // case ApiErrorCode.VALIDATION_FAILED:
case ApiErrorCode.VALIDATION_REQUIRED: // return "Object did not pass validation";
return "Required field empty"; // case ApiErrorCode.VALIDATION_REQUIRED:
case ApiErrorCode.VALIDATION_LENGTH_EXCEEDED: // return "Required field empty";
return "Field too long"; // case ApiErrorCode.VALIDATION_LENGTH_EXCEEDED:
case ApiErrorCode.VALIDATION_INVALID_VALUE: // return "Field too long";
return "Field is set to a non allowed value"; // case ApiErrorCode.VALIDATION_INVALID_VALUE:
case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY: // return "Field is set to a non allowed value";
return "Customized form property is set to required but has an empty value"; // case ApiErrorCode.VALIDATION_CUSTOM_REQUIRED_EMPTY:
case ApiErrorCode.VALIDATION_MISSING_PROPERTY: // return "Customized form property is set to required but has an empty value";
return "Required property is missing entirel"; // case ApiErrorCode.VALIDATION_MISSING_PROPERTY:
case ApiErrorCode.VALIDATION_NOT_UNIQUE: // return "Required property is missing entirel";
return "Field is required to be unique but an existing record with an identical value was found in the database"; // case ApiErrorCode.VALIDATION_NOT_UNIQUE:
case ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE: // return "Field is required to be unique but an existing record with an identical value was found in the database";
return "The start date must be earlier than the end date"; // case ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE:
case ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY: // return "The start date must be earlier than the end date";
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_REFERENTIAL_INTEGRITY:
case ApiErrorCode.VALIDATION_NOT_CHANGEABLE: // 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";
return "the value is fixed and cannot be changed"; // case ApiErrorCode.VALIDATION_NOT_CHANGEABLE:
case ApiErrorCode.CHILD_OBJECT_ERROR: // return "the value is fixed and cannot be changed";
return "Errors in child object during operation"; // case ApiErrorCode.CHILD_OBJECT_ERROR:
// return "Errors in child object during operation";
default: // default:
return null; // return null;
} // }
} }
/* /*
API_CLOSED = 2000, API_CLOSED = 2000,

View File

@@ -73,16 +73,15 @@ namespace AyaNova.Biz
if (!HasErrors) return string.Empty; if (!HasErrors) return string.Empty;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine("Validation errors:"); sb.AppendLine("LT:Errors");
foreach (ValidationError e in _errors) foreach (ValidationError e in _errors)
{ {
var msg = e.Message; var msg = $"LT:{ApiErrorCodeStockMessage.GetTranslationCodeForApiErrorCode(e.Code)}";
if (string.IsNullOrWhiteSpace(msg)) if(!string.IsNullOrWhiteSpace(e.Message))
{ msg+=$" ,{e.Message}";
//msg = e.ErrorType.ToString(); if(!string.IsNullOrWhiteSpace(e.Target) && e.Target!="errorbox")
msg = ApiErrorCodeStockMessage.GetMessage(e.Code); msg+=$" ,field: {e.Target}";
} sb.AppendLine(msg);
sb.AppendLine($"Target: {e.Target} error: {msg}");
} }
return sb.ToString(); return sb.ToString();
} }

View File

@@ -1959,5 +1959,6 @@
"SendPasswordResetCode": "E-Mail zum Zurücksetzen des Passworts senden", "SendPasswordResetCode": "E-Mail zum Zurücksetzen des Passworts senden",
"CopyToClipboard": "In die Zwischenablage kopieren", "CopyToClipboard": "In die Zwischenablage kopieren",
"VendorPopUpNotes": "Popup-Notizen", "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"
} }

View File

@@ -1959,5 +1959,6 @@
"SendPasswordResetCode": "Send password reset email", "SendPasswordResetCode": "Send password reset email",
"CopyToClipboard": "Copy to clipboard", "CopyToClipboard": "Copy to clipboard",
"VendorPopUpNotes": "Pop-up notes", "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"
} }

View File

@@ -1959,5 +1959,6 @@
"SendPasswordResetCode": "Enviar correo electrónico de restablecimiento de contraseña", "SendPasswordResetCode": "Enviar correo electrónico de restablecimiento de contraseña",
"CopyToClipboard": "Copiar al Portapapeles", "CopyToClipboard": "Copiar al Portapapeles",
"VendorPopUpNotes": "Notas emergentes", "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"
} }

View File

@@ -1959,5 +1959,6 @@
"SendPasswordResetCode": "Envoyer un e-mail de réinitialisation du mot de passe", "SendPasswordResetCode": "Envoyer un e-mail de réinitialisation du mot de passe",
"CopyToClipboard": "Copier dans le Presse-papiers", "CopyToClipboard": "Copier dans le Presse-papiers",
"VendorPopUpNotes": "Notes contextuelles", "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"
} }