/// <summary> /// Converts the <paramref name="serializableError"/> to an <see cref="ODataError"/>. /// </summary> /// <param name="serializableError">The <see cref="SerializableError"/> instance to convert.</param> /// <returns>The converted <see cref="ODataError"/></returns> public static ODataError CreateODataError(this SerializableError serializableError) { if (serializableError == null) { throw Error.ArgumentNull(nameof(serializableError)); } //Clone for removal of handled entries var errors = serializableError.ToDictionary(pair => pair.Key, pair => pair.Value); var innerError = errors.ToODataInnerError(); string errorCode = errors.GetPropertyValue <string>(SerializableErrorKeys.ErrorCodeKey); string message = errors.GetPropertyValue <string>(SerializableErrorKeys.MessageKey); errors.Remove(SerializableErrorKeys.ErrorCodeKey); errors.Remove(SerializableErrorKeys.MessageKey); return(new ODataError { ErrorCode = string.IsNullOrWhiteSpace(errorCode) ? null : errorCode, Message = string.IsNullOrWhiteSpace(message) ? errors.ConvertModelStateErrors() : message, Details = errors.CreateErrorDetails(), InnerError = innerError }); }