Ejemplo n.º 1
0
        public static IActionResult ApiErrorMessage400BadRequest(this Controller controller, Exception exc, ModelStateDictionary modelState, string externalRefId)
        {
            //TODO: consider logging

            var errorResponse = new ErrorResponseInfo();

            if (exc == null && modelState == null)
            {
                errorResponse.Error = new Error {
                    Code = "UserIdInTokenNotFound", Message = $"UserId '{externalRefId}' in Bearer token not found in Application data, user needs to be created first"
                };
                return(controller.BadRequest(errorResponse));
            }

            if (exc != null)
            {
                errorResponse.Error = new Error {
                    Code = ValidationErrorCode.UnhandledException.ToString(), DebugMessage = exc.Message, Message = exc.GetType().Name
                };
                return(controller.BadRequest(errorResponse));
            }

            if (modelState != null)
            {
                errorResponse.Error = new Error {
                    Code = "InvalidModelState", Message = modelState.ToString()
                };
                return(controller.BadRequest(errorResponse));
            }

            errorResponse.Error = new Error {
                Code = "UnknownError", Message = "An unknown error occured"
            };
            return(controller.BadRequest(errorResponse));
        }
Ejemplo n.º 2
0
        public static IActionResult ApiErrorMessage400BadRequest(this Controller controller, BusinessLogicException businessLogicException)
        {
            var errorResponse = new ErrorResponseInfo
            {
                Error = new Error
                {
                    Code         = businessLogicException.ErrorCode.ToString(),
                    Message      = $"BusinessLogicException",
                    DebugMessage = businessLogicException.DebugMessage,
                }
            };

            return(controller.BadRequest(errorResponse));
        }