抛出 HttpErrors 时,ServiceStack 不会填充响应 DTO

ServiceStack doesn't populate the response DTO when throwing HttpErrors

ServiceStack 不会在 WebServiceException 的 responseDTO 中填充原始响应 属性。

我是 运行 下面的代码,它应该总是 return 一个 404 响应代码,其中 TestResponse 的 ResponseStatus 属性 填充了 "Some bad request" 但它似乎也就像应该 return 原始的良好响应及其输出 属性 从请求的输入 属性 填充。但是,当我查看 WebServiceException responseDTO

时,我得到了 null
        public TestResponse Post(Test request)
        {
            var response = new TestResponse() { Output = request.Input };

            throw new HttpError(response, (int)HttpStatusCode.BadRequest, "Some bad request");
        }

        public TestResponse Get(Test request)
        {
            try
            {
                using (var client = new JsonServiceClient("http://localhost:5000"))
                {
                    var response =  client.Post(request);
                    return response;
                }
            }
            catch (WebServiceException ex)
            {

                throw;
            }
        }

总的来说,我期望 WebServiceException 中的 responseDTO 属性 将包含端点的 DTO,只要它在抛出 HttpError 时传入,但情况似乎并非如此。我在 responseDTO.

中只看到每个 属性 的默认值和空值

抛出异常时,仅保留 ResponseStatus,您可以将任何其他信息添加到其 Meta 字典中。

或者您可以 return a failed HTTP Response:

public TestResponse Post(Test request)
{
    var response = new TestResponse() { Output = request.Input };

    base.Response.StatusCode = (int)HttpStatusCode.BadRequest;
    return response;
}