mirror of https://github.com/abpframework/abp
#90 Wrap result only for services return object. And only on error case.
parent
2b90ba164b
commit
75e0ed2ee6
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Volo.Abp.AspNetCore.Mvc
|
||||
{
|
||||
public static class ActionResultHelper
|
||||
{
|
||||
public static bool IsObjectResult(Type returnType)
|
||||
{
|
||||
//Get the actual return type (unwrap Task)
|
||||
if (returnType == typeof(Task))
|
||||
{
|
||||
returnType = typeof(void);
|
||||
}
|
||||
else if (returnType.GetTypeInfo().IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>))
|
||||
{
|
||||
returnType = returnType.GenericTypeArguments[0];
|
||||
}
|
||||
|
||||
if (typeof(IActionResult).GetTypeInfo().IsAssignableFrom(returnType))
|
||||
{
|
||||
if (typeof(JsonResult).GetTypeInfo().IsAssignableFrom(returnType) || typeof(ObjectResult).GetTypeInfo().IsAssignableFrom(returnType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Volo.Abp.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface to define a <see cref="LogLevel"/> property (see <see cref="LogLevel"/>).
|
||||
/// </summary>
|
||||
public interface IHasLogLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// Log severity.
|
||||
/// </summary>
|
||||
LogLevel LogLevel { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.Logging;
|
||||
|
||||
namespace Volo.Abp.Ui
|
||||
{
|
||||
/// <summary>
|
||||
/// This exception type is directly shown to the user.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class UserFriendlyException : AbpException, IHasLogLevel, IHasErrorCode
|
||||
{
|
||||
/// <summary>
|
||||
/// Additional information about the exception.
|
||||
/// </summary>
|
||||
public string Details { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// An arbitrary error code.
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Severity of the exception.
|
||||
/// Default: Warn.
|
||||
/// </summary>
|
||||
public LogLevel LogLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public UserFriendlyException()
|
||||
{
|
||||
LogLevel = LogLevel.Warning;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for serializing.
|
||||
/// </summary>
|
||||
public UserFriendlyException(SerializationInfo serializationInfo, StreamingContext context)
|
||||
: base(serializationInfo, context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="message">Exception message</param>
|
||||
public UserFriendlyException(string message)
|
||||
: base(message)
|
||||
{
|
||||
LogLevel = LogLevel.Warning;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="message">Exception message</param>
|
||||
/// <param name="severity">Exception severity</param>
|
||||
public UserFriendlyException(string message, LogLevel logLevel)
|
||||
: base(message)
|
||||
{
|
||||
LogLevel = logLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="code">Error code</param>
|
||||
/// <param name="message">Exception message</param>
|
||||
public UserFriendlyException(int code, string message)
|
||||
: this(message)
|
||||
{
|
||||
Code = code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="message">Exception message</param>
|
||||
/// <param name="details">Additional information about the exception</param>
|
||||
public UserFriendlyException(string message, string details)
|
||||
: this(message)
|
||||
{
|
||||
Details = details;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="code">Error code</param>
|
||||
/// <param name="message">Exception message</param>
|
||||
/// <param name="details">Additional information about the exception</param>
|
||||
public UserFriendlyException(int code, string message, string details)
|
||||
: this(message, details)
|
||||
{
|
||||
Code = code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="message">Exception message</param>
|
||||
/// <param name="innerException">Inner exception</param>
|
||||
public UserFriendlyException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
LogLevel = LogLevel.Warning;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="message">Exception message</param>
|
||||
/// <param name="details">Additional information about the exception</param>
|
||||
/// <param name="innerException">Inner exception</param>
|
||||
public UserFriendlyException(string message, string details, Exception innerException)
|
||||
: this(message, innerException)
|
||||
{
|
||||
Details = details;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue