#17160: Displaying clearer error messages in Live Writer

Work Item: 17160

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-11-28 16:42:32 -08:00
parent e96ea8f47d
commit 737af93b31
5 changed files with 42 additions and 8 deletions

View File

@@ -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 {
handler.Process(context); foreach (var handler in _xmlRpcHandlers) {
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;
} }
} }

View File

@@ -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; }
}
} }

View File

@@ -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));

View File

@@ -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)))));
} }

View File

@@ -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);