private ExceptionResponse GetExceptionResponse(Exception exception)
        {
            // if method is increased, it makes sense to consider creating objects dynamically with reflection.

            ExceptionResponse response;

            response = new ExceptionResponse(exception);
            switch (exception)
            {
            case DbUpdateException updateException when updateException.InnerException != null:
                response.Error = GetDbUpdateExceptionMessage(updateException);
                break;

            case InvalidCredentialException _:
                response.Error = ErrorMessages.UserNotExistsOrPasswordIsWrong;
                break;

            case UnauthorizedAccessException _:
                response.Error = ErrorMessages.UserIsNotAuthorized;
                response.Code  = 401;
                break;
            }

            return(response);
        }
示例#2
0
        private ExceptionResponse GetExceptionResponse(Exception exception)
        {
            // if method is increased, it makes sense to consider creating objects dynamically with reflection.

            ExceptionResponse response;

            response = new ExceptionResponse(exception);

            return(response);
        }