Discussed with Youssef that ODataError right now doesn't support custom error, so we will lose the modelstate's errors in odata error message.
However, ModelState errors are very common in real application to help caller to identify what's wrong with his parameter. We'd better to support it, otherwise user has to parse the modelstate by themselves to convert to ODataError.
Comments: TL:DR - It's obvious ODataError needs to be updated, so to be clear, I'm asking if you can (1) de-internalize ```CreateErrorResponse``` (permanently) and (2) refactor ```ConvertModelStateErrors``` to return a string that a standard JSON parser can consume (a temp. workaround for us.) Something 'like' this 'greedy' version: ``` // Convert the model state errors in to a string (for debugging only). // This should be improved once ODataError allows more details. private static string ConvertModelStateErrors(HttpError error) { StringBuilder builder = new StringBuilder(); foreach (KeyValuePair<string, object> modelStateError in error) { if (modelStateError.Value != null) { StringBuilder valueBuilder = new StringBuilder(); IEnumerable<string> errorMessages = modelStateError.Value as IEnumerable<string>; if (errorMessages != null) { foreach (string errorMessage in errorMessages) { valueBuilder.AppendFormat(",'{0}'", errorMessage); } if (valueBuilder.Length > 0) { valueBuilder.Replace(',', '[', 0, 1); valueBuilder.Append(']'); } } else { valueBuilder.Append(modelStateError.Value); } builder.AppendFormat(",'{0}': '{1}'", modelStateError.Key, valueBuilder.ToString()); } } if (builder.Length > 0) { builder.Remove(0, 1); } return '{' + builder.ToString() + '}'; } ``` If not, I'm going to resort to scrubbing/translating the innererror message so I can pass it through a JSON parser until this issue is 'properly' resolved via ODataError itself. Thanks.
However, ModelState errors are very common in real application to help caller to identify what's wrong with his parameter. We'd better to support it, otherwise user has to parse the modelstate by themselves to convert to ODataError.
Comments: TL:DR - It's obvious ODataError needs to be updated, so to be clear, I'm asking if you can (1) de-internalize ```CreateErrorResponse``` (permanently) and (2) refactor ```ConvertModelStateErrors``` to return a string that a standard JSON parser can consume (a temp. workaround for us.) Something 'like' this 'greedy' version: ``` // Convert the model state errors in to a string (for debugging only). // This should be improved once ODataError allows more details. private static string ConvertModelStateErrors(HttpError error) { StringBuilder builder = new StringBuilder(); foreach (KeyValuePair<string, object> modelStateError in error) { if (modelStateError.Value != null) { StringBuilder valueBuilder = new StringBuilder(); IEnumerable<string> errorMessages = modelStateError.Value as IEnumerable<string>; if (errorMessages != null) { foreach (string errorMessage in errorMessages) { valueBuilder.AppendFormat(",'{0}'", errorMessage); } if (valueBuilder.Length > 0) { valueBuilder.Replace(',', '[', 0, 1); valueBuilder.Append(']'); } } else { valueBuilder.Append(modelStateError.Value); } builder.AppendFormat(",'{0}': '{1}'", modelStateError.Key, valueBuilder.ToString()); } } if (builder.Length > 0) { builder.Remove(0, 1); } return '{' + builder.ToString() + '}'; } ``` If not, I'm going to resort to scrubbing/translating the innererror message so I can pass it through a JSON parser until this issue is 'properly' resolved via ODataError itself. Thanks.