Skip to content

Commit

Permalink
Add exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lewischeng-ms committed Oct 13, 2015
1 parent 7a0718c commit ae170dc
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 56 deletions.
14 changes: 8 additions & 6 deletions src/Microsoft.Restier.Core/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.OData.Edm;
using Microsoft.Restier.Core.Model;
using Microsoft.Restier.Core.Properties;
using Microsoft.Restier.Core.Query;
using Microsoft.Restier.Core.Submit;

Expand Down Expand Up @@ -324,8 +326,7 @@ public static IQueryable<TElement> Source<TElement>(
var elementType = Api.EnsureElementType(context, null, name);
if (typeof(TElement) != elementType)
{
// TODO GitHubIssue#24 : error message
throw new ArgumentException();
throw new ArgumentException(Resources.ElementTypeNotMatch);
}

return Api.SourceCore<TElement>(null, name, arguments);
Expand Down Expand Up @@ -418,8 +419,7 @@ public static IQueryable<TElement> Source<TElement>(
var elementType = Api.EnsureElementType(context, namespaceName, name);
if (typeof(TElement) != elementType)
{
// TODO GitHubIssue#24 : error message
throw new ArgumentException();
throw new ArgumentException(Resources.ElementTypeNotMatch);
}

return Api.SourceCore<TElement>(namespaceName, name, arguments);
Expand Down Expand Up @@ -690,8 +690,10 @@ private static Type EnsureElementType(

if (elementType == null)
{
// TODO GitHubIssue#24 : error message
throw new NotSupportedException();
throw new NotSupportedException(string.Format(
CultureInfo.InvariantCulture,
Resources.ElementTypeNotFound,
name));
}

return elementType;
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.Restier.Core/ApiConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.Restier.Core.Properties;
using Microsoft.Restier.Core.Query;

namespace Microsoft.Restier.Core
Expand Down Expand Up @@ -73,12 +74,12 @@ public ApiConfiguration AddHookHandler<T>(T handler) where T : class, IHookHandl

if (this.IsCommitted)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.ApiConfigurationIsCommitted);
}

if (!typeof(T).IsInterface)
{
throw new InvalidOperationException("Should specify an interface type T for the handler.");
throw new InvalidOperationException(Resources.ShouldBeInterfaceType);
}

var delegateHandler = handler as IDelegateHookHandler<T>;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Restier.Core/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Restier.Core.Properties;

namespace Microsoft.Restier.Core
{
Expand All @@ -26,8 +27,7 @@ public ApiContext(ApiConfiguration configuration)
Ensure.NotNull(configuration, "configuration");
if (!configuration.IsCommitted)
{
// TODO GitHubIssue#24 : error message
throw new ArgumentException();
throw new ArgumentException(Resources.ApiConfigurationShouldBeCommitted);
}

this.Configuration = configuration;
Expand Down
15 changes: 8 additions & 7 deletions src/Microsoft.Restier.Core/ApiData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Restier.Core.Properties;

namespace Microsoft.Restier.Core
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public static class ApiData
public static IQueryable<TElement> Source<TElement>(
string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -64,7 +65,7 @@ public static IQueryable<TElement> Source<TElement>(
public static IQueryable<TElement> Source<TElement>(
string namespaceName, string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -87,7 +88,7 @@ public static IQueryable<TElement> Source<TElement>(
public static IEnumerable<TElement> Results<TElement>(
string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -111,7 +112,7 @@ public static IEnumerable<TElement> Results<TElement>(
public static TResult Result<TResult>(
string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -135,7 +136,7 @@ public static TResult Result<TResult>(
public static IEnumerable<TElement> Results<TElement>(
string namespaceName, string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -159,7 +160,7 @@ public static IEnumerable<TElement> Results<TElement>(
public static TResult Result<TResult>(
string namespaceName, string name, params object[] arguments)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}

/// <summary>
Expand All @@ -181,7 +182,7 @@ public static TResult Result<TResult>(
public static TResult Value<TResult>(
object source, string propertyName)
{
throw new InvalidOperationException();
throw new InvalidOperationException(Resources.DoNotCallApiDataDirectly);
}
}
}
189 changes: 189 additions & 0 deletions src/Microsoft.Restier.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae170dc

Please sign in to comment.