throwing HttpError a valid IHasResponseStatus with errors has no the errors in the result/response...

104 views
Skip to first unread message

csakshaug

unread,
May 31, 2012, 9:20:48 AM5/31/12
to ServiceStack .NET Open Source REST Web Services Framework
response on throw HttpError)
{
"responseStatus": {
"errorCode": "400",
"message": "BadRequest",
"stackTrace": "...",
"errors": []
}
}

response on return response)
{
"responseStatus": {
"errors": [
{
"errorCode": "BadRequest",
"fieldName": "Field1",
"message": "Test123"
},
{
"errorCode": "Error2",
"fieldName": "Field2",
"message": "Test456"
},
{
"errorCode": "Error3",
"fieldName": "Field3",
"message": "Test789"
}
]
}
}


code)

public class TestService : ServiceBase<Test>
{
protected override object Run(Test request)
{
var response = new TestResponse();
response.ResponseStatus = new ResponseStatus();
response.ResponseStatus.Errors = new
List<ResponseError>();
response.ResponseStatus.Errors.Add(new ResponseError()
{ FieldName = "Field1", Message = "Test123", ErrorCode = "Error1" });
response.ResponseStatus.Errors.Add(new ResponseError()
{ FieldName = "Field2", Message = "Test456", ErrorCode = "Error2" });
response.ResponseStatus.Errors.Add(new ResponseError()
{ FieldName = "Field3", Message = "Test789", ErrorCode = "Error3" });

if (request.Throw)
throw new HttpError(response,
HttpStatusCode.BadRequest, "400", "BadRequest");

return response;
}
}

public class Test
{
public bool Throw { get; set; }
}

public class TestResponse : IHasResponseStatus
{
public ResponseStatus ResponseStatus { get; set; }
}

Demis Bellot

unread,
May 31, 2012, 9:28:56 AM5/31/12
to servic...@googlegroups.com
Right just return it if you're manually creating the error response. 
Throwing it overrides and injects the exception into the Errors.

csakshaug

unread,
May 31, 2012, 9:48:16 AM5/31/12
to ServiceStack .NET Open Source REST Web Services Framework
Or throw just

var validation = new ValidationResult();
throw validation.ToException();

On 31 Mai, 15:28, Demis Bellot <demis.bel...@gmail.com> wrote:
> Right just return it if you're manually creating the error response.
> Throwing it overrides and injects the exception into the Errors.
>
Reply all
Reply to author
Forward
0 new messages