开发者

custom error response in WCF data services

In my DataService derrived class I have overriden the HandleException method in order to do custom exception handling (simplified example):

    protected override void HandleException(HandleExceptionArgs args)
    {
       args.Exception = new DataServiceException(
            args.ResponseStatusCode,
            "RecordAlreadyExist",
            "The record with the given ID already exists in the database",
            System.Globalization.CultureInfo.CurrentCulture.Name,
         开发者_Go百科   null);

        base.HandleException(args);
    }

This would result into something like the following JSON response:

    {
       "error": { 
             "code": "RecordAlreadyExist",
             "Message": {
                  "Language": "en-US",
                  "Message": "The record with the given ID already exists in the database"
             }
        }
     }

But I would like to have some additional information in the error response like:

    {
       "error": { 
             "code": "RecordAlreadyExist",
             "Message": {
                  "Language": "en-US",
                  "Message": "The record with the given ID already exists in the database"
             },
             "RecordID": "1234"
        }
     }

How can I do that? DataServiceException only supports an error code and a message...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜