forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorViewAttribute.cs
More file actions
27 lines (24 loc) · 846 Bytes
/
Copy pathErrorViewAttribute.cs
File metadata and controls
27 lines (24 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using ServiceStack.Web;
namespace ServiceStack
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class ErrorViewAttribute : RequestFilterAttribute
{
public string FieldName { get; set; }
public ErrorViewAttribute() : this("ErrorView") {}
public ErrorViewAttribute(string fieldName)
{
FieldName = fieldName;
Priority = -1;
}
public override void Execute(IRequest req, IResponse res, object requestDto)
{
var errorViewGetter = TypeProperties.Get(requestDto.GetType()).GetPublicGetter(FieldName);
if (errorViewGetter?.Invoke(requestDto) is string errorView)
{
req.SetErrorView(errorView);
}
}
}
}