Skip to content

Commit 72feaf8

Browse files
committed
Refactor error messages in Contentstack Management Core
1 parent 435e9cc commit 72feaf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+295
-125
lines changed

Contentstack.Management.Core.Unit.Tests/Utils/CSConstantsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public void Test_CSConstants_InternalConstants()
3030
public void Test_CSConstants_InternalMessages()
3131
{
3232
Assert.AreEqual("You are already logged in.", CSConstants.YouAreLoggedIn);
33-
Assert.AreEqual("You are need to login.", CSConstants.YouAreNotLoggedIn);
34-
Assert.AreEqual("Uid should not be empty.", CSConstants.MissingUID);
35-
Assert.AreEqual("API Key should not be empty.", CSConstants.MissingAPIKey);
33+
Assert.AreEqual("You are not logged in. Log in and try again.", CSConstants.YouAreNotLoggedIn);
34+
Assert.AreEqual("UID is required. Provide a valid UID and try again.", CSConstants.MissingUID);
35+
Assert.AreEqual("API Key is required. Provide a valid API Key and try again.", CSConstants.MissingAPIKey);
3636
Assert.AreEqual("API Key should be empty.", CSConstants.APIKey);
3737
Assert.AreEqual("Please enter email id to remove from org.", CSConstants.RemoveUserEmailError);
3838
Assert.AreEqual("Please enter share uid to resend invitation.", CSConstants.OrgShareUIDMissing);

Contentstack.Management.Core/ContentstackClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public Task<ContentstackResponse> LogoutAsync(string authtoken = null)
485485
public OAuthHandler OAuth(OAuthOptions options)
486486
{
487487
if (options == null)
488-
throw new ArgumentNullException(nameof(options), "OAuth options cannot be null.");
488+
throw new ArgumentNullException(nameof(options), CSConstants.OAuthOptionsRequired);
489489

490490
return new OAuthHandler(this, options);
491491
}
@@ -519,10 +519,10 @@ public OAuthHandler OAuth()
519519
internal void SetOAuthTokens(OAuthTokens tokens)
520520
{
521521
if (tokens == null)
522-
throw new ArgumentNullException(nameof(tokens), "OAuth tokens cannot be null.");
522+
throw new ArgumentNullException(nameof(tokens), CSConstants.OAuthTokensRequired);
523523

524524
if (string.IsNullOrEmpty(tokens.AccessToken))
525-
throw new ArgumentException("Access token cannot be null or empty.", nameof(tokens));
525+
throw new ArgumentException(CSConstants.AccessTokenRequired, nameof(tokens));
526526

527527
// Store the access token in the client options for use in HTTP requests
528528
// This will be used by the HTTP pipeline to inject the Bearer token
@@ -541,7 +541,7 @@ internal void SetOAuthTokens(OAuthTokens tokens)
541541
public OAuthTokens GetOAuthTokens(string clientId)
542542
{
543543
if (string.IsNullOrEmpty(clientId))
544-
throw new ArgumentException("Client ID cannot be null or empty.", nameof(clientId));
544+
throw new ArgumentException(CSConstants.ClientIDRequired, nameof(clientId));
545545

546546
return GetStoredOAuthTokens(clientId);
547547
}
@@ -607,7 +607,7 @@ public void ClearOAuthTokens(string clientId = null)
607607
internal void StoreOAuthTokens(string clientId, OAuthTokens tokens)
608608
{
609609
if (string.IsNullOrEmpty(clientId))
610-
throw new ArgumentException("Client ID cannot be null or empty.", nameof(clientId));
610+
throw new ArgumentException(CSConstants.ClientIDRequired, nameof(clientId));
611611

612612
if (tokens == null)
613613
throw new ArgumentNullException(nameof(tokens));

Contentstack.Management.Core/Models/Asset.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Contentstack.Management.Core.Queryable;
44
using Contentstack.Management.Core.Services.Models;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models
78
{
@@ -359,15 +360,15 @@ internal void ThrowIfUidNotEmpty()
359360
{
360361
if (!string.IsNullOrEmpty(this.Uid))
361362
{
362-
throw new InvalidOperationException("Operation not allowed.");
363+
throw new InvalidOperationException(CSConstants.AssetAlreadyExists);
363364
}
364365
}
365366

366367
internal void ThrowIfUidEmpty()
367368
{
368369
if (string.IsNullOrEmpty(this.Uid))
369370
{
370-
throw new InvalidOperationException("Uid can not be empty.");
371+
throw new InvalidOperationException(CSConstants.AssetUIDRequired);
371372
}
372373
}
373374
#endregion

Contentstack.Management.Core/Models/AssetModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Net.Http;
44
using Contentstack.Management.Core.Abstractions;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models
78
{
@@ -29,11 +30,11 @@ public AssetModel(string fileName, ByteArrayContent byteArray, string contentTyp
2930
{
3031
if (fileName == null)
3132
{
32-
throw new ArgumentNullException("fileName", "File name can not be null.");
33+
throw new ArgumentNullException("fileName", CSConstants.FileNameRequired);
3334
}
3435
if (byteArray == null)
3536
{
36-
throw new ArgumentNullException("byteArray", "Uploading content can not be null.");
37+
throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired);
3738
}
3839
FileName = fileName;
3940
Title = title;

Contentstack.Management.Core/Models/AuditLog.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Contentstack.Management.Core.Queryable;
44
using Contentstack.Management.Core.Services.Models;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models
78
{
@@ -107,15 +108,15 @@ internal void ThrowIfUidNotEmpty()
107108
{
108109
if (!string.IsNullOrEmpty(this.Uid))
109110
{
110-
throw new InvalidOperationException("Operation not allowed.");
111+
throw new InvalidOperationException(CSConstants.OperationNotAllowedOnAuditLogs);
111112
}
112113
}
113114

114115
internal void ThrowIfUidEmpty()
115116
{
116117
if (string.IsNullOrEmpty(this.Uid))
117118
{
118-
throw new InvalidOperationException("Uid can not be empty.");
119+
throw new InvalidOperationException(CSConstants.AuditLogUIDRequired);
119120
}
120121
}
121122
#endregion

Contentstack.Management.Core/Models/BaseModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Contentstack.Management.Core.Queryable;
44
using Contentstack.Management.Core.Services.Models;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models
78
{
@@ -19,7 +20,7 @@ public BaseModel(Stack stack, string fieldName, string uid = null)
1920
stack.ThrowIfAPIKeyEmpty();
2021
if (fieldName == null)
2122
{
22-
throw new ArgumentNullException("fieldName", "Field name mandatory for service");
23+
throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired);
2324
}
2425
this.stack = stack;
2526
this.fieldName = fieldName;
@@ -105,15 +106,15 @@ internal void ThrowIfUidNotEmpty()
105106
{
106107
if (!string.IsNullOrEmpty(this.Uid))
107108
{
108-
throw new InvalidOperationException("Operation not allowed.");
109+
throw new InvalidOperationException(CSConstants.OperationNotAllowedOnModel);
109110
}
110111
}
111112

112113
internal void ThrowIfUidEmpty()
113114
{
114115
if (string.IsNullOrEmpty(this.Uid))
115116
{
116-
throw new InvalidOperationException("Uid can not be empty.");
117+
throw new InvalidOperationException(CSConstants.MissingUID);
117118
}
118119
}
119120
#endregion

Contentstack.Management.Core/Models/CustomExtension/CustomFieldModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Net.Http;
44
using Contentstack.Management.Core.Abstractions;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models.CustomExtension
78
{
@@ -32,11 +33,11 @@ public CustomFieldModel(ByteArrayContent byteArray, string contentType, string t
3233

3334
if (byteArray == null)
3435
{
35-
throw new ArgumentNullException("byteArray", "Uploading content can not be null.");
36+
throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired);
3637
}
3738
if (title == null)
3839
{
39-
throw new ArgumentNullException("title", "Title for widget is required.");
40+
throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired);
4041
}
4142
Title = title;
4243
DataType = dataType;

Contentstack.Management.Core/Models/CustomExtension/CustomWidgetModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Net.Http;
55
using System.Net.Http.Headers;
66
using Contentstack.Management.Core.Abstractions;
7+
using Contentstack.Management.Core.Utils;
78
using Newtonsoft.Json;
89

910
namespace Contentstack.Management.Core.Models.CustomExtension
@@ -33,11 +34,11 @@ public CustomWidgetModel(ByteArrayContent byteArray, string contentType, string
3334
{
3435
if (byteArray == null)
3536
{
36-
throw new ArgumentNullException("byteArray", "Uploading content can not be null.");
37+
throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired);
3738
}
3839
if (title == null)
3940
{
40-
throw new ArgumentNullException("title", "Title for widget is required.");
41+
throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired);
4142
}
4243
Title = title;
4344
Tags = tags;

Contentstack.Management.Core/Models/CustomExtension/DashboardWidgetModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Net.Http;
44
using Contentstack.Management.Core.Abstractions;
5+
using Contentstack.Management.Core.Utils;
56

67
namespace Contentstack.Management.Core.Models.CustomExtension
78
{
@@ -32,11 +33,11 @@ public DashboardWidgetModel(ByteArrayContent byteArray, string contentType, stri
3233

3334
if (byteArray == null)
3435
{
35-
throw new ArgumentNullException("byteArray", "Uploading content can not be null.");
36+
throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired);
3637
}
3738
if (title == null)
3839
{
39-
throw new ArgumentNullException("title", "Title for widget is required.");
40+
throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired);
4041
}
4142
Title = title;
4243
Tags = tags;

Contentstack.Management.Core/Models/Extension.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Contentstack.Management.Core.Abstractions;
44
using Contentstack.Management.Core.Queryable;
55
using Contentstack.Management.Core.Services.Models;
6+
using Contentstack.Management.Core.Utils;
67

78
namespace Contentstack.Management.Core.Models
89
{
@@ -246,15 +247,15 @@ internal void ThrowIfUidNotEmpty()
246247
{
247248
if (!string.IsNullOrEmpty(this.Uid))
248249
{
249-
throw new InvalidOperationException("Operation not allowed.");
250+
throw new InvalidOperationException(CSConstants.OperationNotAllowedOnExtension);
250251
}
251252
}
252253

253254
internal void ThrowIfUidEmpty()
254255
{
255256
if (string.IsNullOrEmpty(this.Uid))
256257
{
257-
throw new InvalidOperationException("Uid can not be empty.");
258+
throw new InvalidOperationException(CSConstants.ExtensionUIDRequired);
258259
}
259260
}
260261
#endregion

0 commit comments

Comments
 (0)