Hi, I’m having some trouble trying to get a custom response error from my Attribute:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class TestAttribute : AuthenticateAttribute
{
public override void Execute(IRequest req, IResponse res, object requestDto)
{
if (req.Verb == "POST")
{
var responseDto = new ErrorResponse
{
ResponseStatus = new ResponseStatus
{
ErrorCode = GetType().Name,
Message = "Test Conflict",
Errors = new List<ResponseError>
{
new ResponseError
{
ErrorCode = "NotEmpty",
FieldName = "Company",
Message = "'Company' should not be empty."
}
},
Meta = new Dictionary<string, string>
{
{"foo", "bar"},
{"qwe", "asd"}
}
}
};
throw new HttpError(HttpStatusCode.Conflict, "Conflict")
{
Response = responseDto
};
}
}
}
For semplicity I just created a test attribute to return the error object on my service POST request.
I’m getting the correct status code ErrorCode
(409) and Message
(Test Conflict) but nothing is returned as response, just a {}
where I want the Errors
and Meta
objects.
To be complete I have this config setup:
var hostConfig = new HostConfig();
hostConfig.DebugMode = true;
hostConfig.WriteErrorsToResponse = true;
hostConfig.AllowJsonpRequests = false;
SetConfig(hostConfig);
What am I missing? Is there a way to get that ErrorResponse
back from my attribute?