mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 04:43:35 +08:00
#17160: Displaying clearer error messages in Live Writer
Work Item: 17160 --HG-- branch : 1.x
This commit is contained in:
@@ -35,8 +35,21 @@ namespace Orchard.Core.XmlRpc.Controllers {
|
|||||||
|
|
||||||
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
|
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
|
||||||
var context = new XmlRpcContext { ControllerContext = ControllerContext, HttpContext = HttpContext, Request = request };
|
var context = new XmlRpcContext { ControllerContext = ControllerContext, HttpContext = HttpContext, Request = request };
|
||||||
foreach (var handler in _xmlRpcHandlers)
|
try {
|
||||||
|
foreach (var handler in _xmlRpcHandlers) {
|
||||||
handler.Process(context);
|
handler.Process(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OrchardCoreException e) {
|
||||||
|
// if a core exception is raised, report the error message, otherwise signal a 500
|
||||||
|
context.Response = context.Response ?? new XRpcMethodResponse();
|
||||||
|
|
||||||
|
context.Response.Fault = new XRpcFault {
|
||||||
|
Code = 0,
|
||||||
|
Message = e.LocalizedMessage.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return context.Response;
|
return context.Response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,4 +39,9 @@ namespace Orchard.Core.XmlRpc.Models {
|
|||||||
|
|
||||||
public override Type Type { get { return typeof(T); } }
|
public override Type Type { get { return typeof(T); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class XRpcFault {
|
||||||
|
public string Message { get; set; }
|
||||||
|
public int Code { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
@@ -5,6 +5,7 @@ namespace Orchard.Core.XmlRpc.Models {
|
|||||||
public XRpcMethodResponse() { Params = new List<XRpcData>(); }
|
public XRpcMethodResponse() { Params = new List<XRpcData>(); }
|
||||||
|
|
||||||
public IList<XRpcData> Params { get; set; }
|
public IList<XRpcData> Params { get; set; }
|
||||||
|
public XRpcFault Fault { get; set; }
|
||||||
|
|
||||||
public XRpcMethodResponse Add<T>(T value) {
|
public XRpcMethodResponse Add<T>(T value) {
|
||||||
Params.Add(XRpcData.For(value));
|
Params.Add(XRpcData.For(value));
|
||||||
|
@@ -41,10 +41,24 @@ namespace Orchard.Core.XmlRpc.Services {
|
|||||||
public XElement MapMethodResponse(XRpcMethodResponse rpcMethodResponse) {
|
public XElement MapMethodResponse(XRpcMethodResponse rpcMethodResponse) {
|
||||||
Argument.ThrowIfNull(rpcMethodResponse, "rpcMethodResponse");
|
Argument.ThrowIfNull(rpcMethodResponse, "rpcMethodResponse");
|
||||||
|
|
||||||
return new XElement(
|
// return a valid fault as per http://xmlrpc.scripting.com/spec.html
|
||||||
"methodResponse",
|
if(rpcMethodResponse.Fault != null) {
|
||||||
new XElement(
|
return new XElement("methodResponse",
|
||||||
"params",
|
new XElement("fault",
|
||||||
|
new XElement("value",
|
||||||
|
new XElement("struct",
|
||||||
|
new XElement("member",
|
||||||
|
new XElement("name", "faultCode"),
|
||||||
|
new XElement("value",
|
||||||
|
new XElement("int", rpcMethodResponse.Fault.Code))),
|
||||||
|
new XElement("member",
|
||||||
|
new XElement("name", "faultString"),
|
||||||
|
new XElement("value",
|
||||||
|
new XElement("string", rpcMethodResponse.Fault.Message)))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new XElement("methodResponse",
|
||||||
|
new XElement("params",
|
||||||
rpcMethodResponse.Params.Select(
|
rpcMethodResponse.Params.Select(
|
||||||
p => new XElement("param", MapValue(p)))));
|
p => new XElement("param", MapValue(p)))));
|
||||||
}
|
}
|
||||||
|
@@ -257,8 +257,9 @@ namespace Orchard.Blogs.Services {
|
|||||||
|
|
||||||
IUser user = ValidateUser(userName, password);
|
IUser user = ValidateUser(userName, password);
|
||||||
var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);
|
var blogPost = _blogPostService.Get(postId, VersionOptions.DraftRequired);
|
||||||
if (blogPost == null)
|
if (blogPost == null) {
|
||||||
throw new ArgumentException();
|
throw new OrchardCoreException(T("The specified Blog Post doesn't exist anymore. Please create a new Blog Post."));
|
||||||
|
}
|
||||||
|
|
||||||
_authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);
|
_authorizationService.CheckAccess(publish ? Permissions.PublishBlogPost : Permissions.EditBlogPost, user, blogPost);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user