AB#6233 - Clean up

This commit is contained in:
Bjarke Berg
2020-05-07 10:21:32 +02:00
parent e3f9b94fd0
commit e121ce136f
5 changed files with 19 additions and 22 deletions

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization;
namespace Umbraco.Core.Exceptions
namespace Umbraco.Web.Common.Exceptions
{
[Serializable]
public class HttpResponseException : Exception
@@ -39,5 +39,16 @@ namespace Umbraco.Core.Exceptions
base.GetObjectData(info, context);
}
public static HttpResponseException CreateValidationErrorResponse(object model)
{
return new HttpResponseException(HttpStatusCode.BadRequest, model)
{
AdditionalHeaders =
{
["X-Status-Reason"] = "Validation failed"
}
};
}
}
}

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Common.Exceptions;
namespace Umbraco.Web.Common.Filters
{

View File

@@ -1,17 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Migrations.Install;
using Umbraco.Net;
using Umbraco.Web.Common.Attributes;
using Umbraco.Web.Common.Exceptions;
using Umbraco.Web.Install;
using Umbraco.Web.Install.Models;
@@ -152,32 +151,20 @@ namespace Umbraco.Web.Common.Install
var installException = ex as InstallException;
if (installException != null)
{
throw new HttpResponseException(HttpStatusCode.BadRequest, new
throw HttpResponseException.CreateValidationErrorResponse(new
{
view = installException.View,
model = installException.ViewModel,
message = installException.Message
})
{
AdditionalHeaders =
{
["X-Status-Reason"] = "Validation failed"
}
};
});
}
throw new HttpResponseException(HttpStatusCode.BadRequest,new
throw HttpResponseException.CreateValidationErrorResponse(new
{
step = step.Name,
view = "error",
message = ex.Message
})
{
AdditionalHeaders =
{
["X-Status-Reason"] = "Validation failed"
}
};
});
}
}

View File

@@ -85,7 +85,7 @@ namespace Umbraco.Web.Macros
{
object key = 0;
if (_umbracoContextAccessor.UmbracoContext.Security.IsAuthenticated())
if (_umbracoContextAccessor.GetRequiredUmbracoContext().Security.IsAuthenticated())
{
key = _memberUserKeyProvider.GetMemberProviderUserKey() ?? 0;
}

View File

@@ -74,8 +74,6 @@ namespace Umbraco.Web.Common.Macros
//lets render this controller as a child action
var viewContext = new ViewContext();
//try and extract the current view context from the route values, this would be set in the UmbracoViewPage or in
// the UmbracoPageResult if POSTing to an MVC controller but rendering in Webforms
routeVals.DataTokens.Add("ParentActionViewContext", viewContext);