diff --git a/Contentstack.Core/ContentstackClient.cs b/Contentstack.Core/ContentstackClient.cs index 69dd881..5a3fdb7 100644 --- a/Contentstack.Core/ContentstackClient.cs +++ b/Contentstack.Core/ContentstackClient.cs @@ -136,7 +136,7 @@ public ContentstackClient(IOptions options) } else { - throw new InvalidOperationException("Add PreviewToken or ManagementToken in LivePreviewConfig"); + throw new InvalidOperationException(ErrorMessages.LivePreviewTokenMissing); } } this.SerializerSettings.DateParseHandling = DateParseHandling.None; @@ -338,7 +338,7 @@ public async Task GetContentTypes(Dictionary param = null } catch (Exception ex) { - throw GetContentstackError(ex); + throw new GetContentstackError(string.Format(ErrorMessages.ContentstackClientRequestError, ex.Message), ex); } } @@ -372,7 +372,7 @@ private async Task GetLivePreviewData() } else { - throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + throw new InvalidOperationException(ErrorMessages.LivePreviewTokenMissing); } if (!string.IsNullOrEmpty(this.LivePreviewConfig.ReleaseId)) @@ -873,7 +873,7 @@ private async Task GetResultAsync(string Init = "false", SyncType Syn } catch (Exception ex) { - throw GetContentstackError(ex); + throw new GetContentstackError(string.Format(ErrorMessages.ContentstackSyncRequestError, ex.Message), ex); } } #endregion diff --git a/Contentstack.Core/Internals/AssetJsonConverter.cs b/Contentstack.Core/Internals/AssetJsonConverter.cs index 9eee45a..677682d 100644 --- a/Contentstack.Core/Internals/AssetJsonConverter.cs +++ b/Contentstack.Core/Internals/AssetJsonConverter.cs @@ -20,7 +20,7 @@ public override Asset ReadJson(JsonReader reader, Type objectType, Asset existin public override void WriteJson(JsonWriter writer, Asset value, JsonSerializer serializer) { - throw new NotImplementedException(); + throw AssetException.CreateForJsonConversionError(); } } } diff --git a/Contentstack.Core/Internals/ContentstackConvert.cs b/Contentstack.Core/Internals/ContentstackConvert.cs index a35a235..369bc32 100644 --- a/Contentstack.Core/Internals/ContentstackConvert.cs +++ b/Contentstack.Core/Internals/ContentstackConvert.cs @@ -15,12 +15,12 @@ public static Int32 ToInt32(object input) { output = Convert.ToInt32(input); } - catch (Exception e) - { - if (e.Source != null) - { - Console.WriteLine("IOException source: {0}", e.Source); - } + catch (Exception e) + { + if (e.Source != null) + { + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); + } } return output; @@ -34,12 +34,12 @@ public static bool ToBoolean(object input) { output = Convert.ToBoolean(input); } - catch (Exception e) - { - if (e.Source != null) - { - Console.WriteLine("IOException source: {0}", e.Source); - } + catch (Exception e) + { + if (e.Source != null) + { + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); + } } return output; @@ -52,13 +52,13 @@ public static string ToString(object input, string defaultValue = "") try { output = Convert.ToString(input); - } - catch (Exception e) - { - if (e.Source != null) - { - Console.WriteLine("IOException source: {0}", e.Source); - } + } + catch (Exception e) + { + if (e.Source != null) + { + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); + } } return output; @@ -76,7 +76,7 @@ public static double ToDouble(object input) { if (e.Source != null) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } } @@ -90,15 +90,15 @@ public static decimal ToDecimal(object input) try { output = Convert.ToDecimal(input); - } - catch (Exception e) - { - if (e.Source != null) - { - Console.WriteLine("IOException source: {0}", e.Source); - } - } - + } + catch (Exception e) + { + if (e.Source != null) + { + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); + } + } + return output; } @@ -109,20 +109,20 @@ public static DateTime ToDateTime(object input) try { output = DateTime.Parse(ContentstackConvert.ToString(input)); - } - catch (Exception e) - { - if (e.Source != null) - { - Console.WriteLine("IOException source: {0}", e.Source); - } - } - + } + catch (Exception e) + { + if (e.Source != null) + { + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); + } + } + return output; } public static string ToISODate(object input) - { + { DateTime now = DateTime.Now; try { @@ -132,7 +132,7 @@ public static string ToISODate(object input) { if (e.Source != null) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } } return now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'sszzz"); @@ -186,7 +186,7 @@ public static object GetValue(string value) { if (e.Source != null) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } } @@ -222,8 +222,8 @@ public static RegexOptions GetRegexOptions(string option) return RegexOptions.None; } } - } - + } + public static Stream GenerateStreamFromString(string s) { MemoryStream stream = new MemoryStream(); @@ -232,7 +232,7 @@ public static Stream GenerateStreamFromString(string s) writer.Flush(); stream.Position = 0; return stream; - } + } #endregion diff --git a/Contentstack.Core/Internals/ContentstackExceptions.cs b/Contentstack.Core/Internals/ContentstackExceptions.cs new file mode 100644 index 0000000..320d412 --- /dev/null +++ b/Contentstack.Core/Internals/ContentstackExceptions.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Net; + +namespace Contentstack.Core.Internals +{ + /// + /// Base exception class for all Contentstack exceptions + /// + public class ContentstackException : Exception + { + public int ErrorCode { get; set; } + public HttpStatusCode StatusCode { get; set; } + public Dictionary Errors { get; set; } + + public ContentstackException() : base() + { + } + + public ContentstackException(string message) : base(message) + { + } + + public ContentstackException(string message, Exception innerException) : base(message, innerException) + { + } + + public ContentstackException(Exception ex) : base(ex.Message, ex) + { + } + } + + /// + /// Exception thrown when there are issues with query filters or parameters + /// + public class QueryFilterException : ContentstackException + { + public QueryFilterException() : base(ErrorMessages.QueryFilterError) + { + } + + public QueryFilterException(string message) : base(message) + { + } + + public QueryFilterException(string message, Exception innerException) : base(message, innerException) + { + } + + public static QueryFilterException Create(Exception innerException = null) + { + return new QueryFilterException( + string.Format(ErrorMessages.InvalidParamsError, + innerException?.Message ?? ErrorMessages.QueryFilterError), + innerException); + } + } + + /// + /// Exception thrown when there are asset-related errors + /// + public class AssetException : ContentstackException + { + public AssetException(string message) : base(message) + { + } + + public AssetException(string message, Exception innerException) : base(message, innerException) + { + } + + public static AssetException CreateForJsonConversionError() + { + return new AssetException(ErrorMessages.AssetJsonConversionError); + } + + public static AssetException CreateForProcessingError(Exception innerException) + { + return new AssetException( + string.Format(ErrorMessages.AssetProcessingError, + ErrorMessages.FormatExceptionDetails(innerException)), + innerException); + } + } + + /// + /// Exception thrown when there are live preview-related errors + /// + public class LivePreviewException : ContentstackException + { + public LivePreviewException() : base(ErrorMessages.LivePreviewTokenMissing) + { + } + + public LivePreviewException(string message) : base(message) + { + } + + public LivePreviewException(string message, Exception innerException) : base(message, innerException) + { + } + } + + /// + /// Exception thrown when there are global field-related errors + /// + public class GlobalFieldException : ContentstackException + { + public GlobalFieldException(string message) : base(message) + { + } + + public GlobalFieldException(string message, Exception innerException) : base(message, innerException) + { + } + + public static GlobalFieldException CreateForProcessingError(Exception innerException) + { + return new GlobalFieldException( + string.Format(ErrorMessages.GlobalFieldProcessingError, + ErrorMessages.FormatExceptionDetails(innerException)), + innerException); + } + + public static GlobalFieldException CreateForIdNull() + { + return new GlobalFieldException(ErrorMessages.GlobalFieldIdNullError); + } + } + + /// + /// Exception thrown when there are entry-related errors + /// + public class EntryException : ContentstackException + { + public EntryException(string message) : base(message) + { + } + + public EntryException(string message, Exception innerException) : base(message, innerException) + { + } + + public static EntryException CreateForProcessingError(Exception innerException) + { + return new EntryException( + string.Format(ErrorMessages.EntryProcessingError, + ErrorMessages.FormatExceptionDetails(innerException)), + innerException); + } + } + + /// + /// Exception thrown when there are taxonomy-related errors + /// + public class TaxonomyException : ContentstackException + { + public TaxonomyException(string message) : base(message) + { + } + + public TaxonomyException(string message, Exception innerException) : base(message, innerException) + { + } + + public static TaxonomyException CreateForProcessingError(Exception innerException) + { + return new TaxonomyException( + string.Format(ErrorMessages.TaxonomyProcessingError, + ErrorMessages.FormatExceptionDetails(innerException)), + innerException); + } + } + + /// + /// Exception thrown when there are content type-related errors + /// + public class ContentTypeException : ContentstackException + { + public ContentTypeException(string message) : base(message) + { + } + + public ContentTypeException(string message, Exception innerException) : base(message, innerException) + { + } + + public static ContentTypeException CreateForProcessingError(Exception innerException) + { + return new ContentTypeException( + ErrorMessages.ContentTypeProcessingError, + innerException); + } + } +} \ No newline at end of file diff --git a/Contentstack.Core/Internals/ErrorMessages.cs b/Contentstack.Core/Internals/ErrorMessages.cs new file mode 100644 index 0000000..1c4b150 --- /dev/null +++ b/Contentstack.Core/Internals/ErrorMessages.cs @@ -0,0 +1,74 @@ +using System; + +namespace Contentstack.Core.Internals +{ + /// + /// Contains all error message constants used throughout the SDK + /// + internal static class ErrorMessages + { + // Query and Filter related errors + public const string QueryFilterError = "Please provide valid params."; + public const string InvalidParamsError = "Invalid parameters provided. {0}"; + + // Asset related errors + public const string AssetJsonConversionError = "Failed to convert asset JSON. Please check the asset format and data integrity."; + public const string AssetProcessingError = "An error occurred while processing the asset. {0}"; + public const string AssetLibraryRequestError = "Exception in {0}: {1}\nStackTrace: {2}"; + + // Entry related errors + public const string EntryProcessingError = "An error occurred while processing the entry. {0}"; + public const string EntryUidRequired = "Please set entry uid."; + public const string EntryNotFoundInCache = "Entry is not present in cache"; + + // Global Field related errors + public const string GlobalFieldIdNullError = "GlobalFieldId required. This value cannot be null or empty, define it in your configuration."; + public const string GlobalFieldProcessingError = "An error occurred while processing the globalField. {0}"; + public const string GlobalFieldQueryError = "Global field query failed. Check your query syntax and field schema before retrying."; + + // Live Preview related errors + public const string LivePreviewTokenMissing = "Live Preview token missing. Add either a PreviewToken or a ManagementToken in the LivePreviewConfig."; + + // Client Request related errors + public const string ContentstackClientRequestError = "Contentstack client request failed. Check your network settings or request parameters and try again: {0}"; + public const string ContentstackSyncRequestError = "An error occurred while processing the Contentstack client request: {0}"; + + // Taxonomy related errors + public const string TaxonomyProcessingError = "An error occurred while processing the taxonomy operation: {0}"; + + // Content Type related errors + public const string ContentTypeProcessingError = "Content type processing failed. Verify the schema and ensure all required fields are configured."; + + // Authentication and Configuration errors + public const string StackApiKeyRequired = "Stack api key can not be null."; + public const string AccessTokenRequired = "Access token can not be null."; + public const string EnvironmentRequired = "Environment can not be null."; + public const string AuthenticationNotPresent = "Authentication Not present."; + public const string ContentTypeNameRequired = "Please set contentType name."; + + // JSON and Parsing errors + public const string InvalidJsonFormat = "Please provide valid JSON."; + public const string ParsingError = "Parsing Error."; + + // Network and Server errors + public const string NoConnectionError = "Connection error"; + public const string ServerError = "Server interaction went wrong, Please try again."; + public const string NetworkUnavailable = "Network not available."; + public const string DefaultError = "Oops! Something went wrong. Please try again."; + + // Cache related errors + public const string SavingNetworkCallResponseForCache = "Error while saving network call response."; + + // Initialization errors + public const string ContentstackDefaultMethodNotCalled = "You must called Contentstack.stack() first"; + + // Helper method to format exception details + public static string FormatExceptionDetails(Exception ex) + { + return string.Format("Exception: {0}\nSource: {1}\nStackTrace: {2}", + ex.Message, + ex.Source ?? "Unknown", + ex.StackTrace ?? "No stack trace available"); + } + } +} \ No newline at end of file diff --git a/Contentstack.Core/Internals/StackOutput.cs b/Contentstack.Core/Internals/StackOutput.cs index 0b20489..235acc1 100644 --- a/Contentstack.Core/Internals/StackOutput.cs +++ b/Contentstack.Core/Internals/StackOutput.cs @@ -218,20 +218,20 @@ internal class StackOutput // } // } - // if (output.ContainsKey("asset")) - // { - // if (output["asset"].GetType() == typeof(string)) - // { - // this._Object = output["asset"]; - // } - // else - // { - // this._Object = output["asset"]; - // //var tmp = this._Objects as object[]; - // //if (tmp != null) - // // this._Object = tmp.FirstOrDefault(); - // } - // } + // if (output.ContainsKey("asset")) + // { + // if (output["asset"].GetType() == typeof(string)) + // { + // this._Object = output["asset"]; + // } + // else + // { + // this._Object = output["asset"]; + // //var tmp = this._Objects as object[]; + // //if (tmp != null) + // // this._Object = tmp.FirstOrDefault(); + // } + // } // if (output.ContainsKey("assets")) // { // if (output["assets"].GetType() == typeof(string)) @@ -305,7 +305,7 @@ internal class StackOutput // } // catch (Exception ex) // { - // throw new ContentstackError(ex); + // throw new ContentstackError($"Failed to generate stack output: {ex.Message}\nStackTrace: {ex.StackTrace}"); // } // } // public Dictionary GetObjectDict(JContainer container) diff --git a/Contentstack.Core/Models/Asset.cs b/Contentstack.Core/Models/Asset.cs index dcc07e9..a2a0d6b 100644 --- a/Contentstack.Core/Models/Asset.cs +++ b/Contentstack.Core/Models/Asset.cs @@ -64,7 +64,7 @@ public object this[string key] { if (e.Source != null) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } } } @@ -252,7 +252,7 @@ public Asset IncludeMetadata() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -322,7 +322,7 @@ public DateTime GetCreateAt() catch (Exception e) { if (e.Source != null) - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } return DateTime.MinValue; } @@ -362,7 +362,7 @@ public DateTime GetUpdateAt() catch (Exception e) { if (e.Source != null) - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } return DateTime.MinValue; } @@ -384,7 +384,7 @@ public DateTime GetDeleteAt() catch (Exception e) { if (e.Source != null) - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } return DateTime.MinValue; } @@ -424,7 +424,7 @@ public async Task Fetch() } catch (Exception ex) { - throw GetContentstackError(ex); + throw AssetException.CreateForProcessingError(ex); } } diff --git a/Contentstack.Core/Models/AssetLibrary.cs b/Contentstack.Core/Models/AssetLibrary.cs index 8ec17e8..102c5dc 100644 --- a/Contentstack.Core/Models/AssetLibrary.cs +++ b/Contentstack.Core/Models/AssetLibrary.cs @@ -100,7 +100,7 @@ public AssetLibrary Query(JObject QueryObject) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -124,7 +124,7 @@ public AssetLibrary IncludeFallback() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -149,7 +149,7 @@ public AssetLibrary IncludeBranch() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -241,7 +241,7 @@ public AssetLibrary IncludeMetadata() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -285,7 +285,7 @@ public AssetLibrary Skip(int number) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -311,7 +311,7 @@ public AssetLibrary Limit(int number) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -340,7 +340,7 @@ public AssetLibrary Tags(string[] tags) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -369,7 +369,7 @@ public AssetLibrary Only(String[] fieldUid) } catch (Exception e) { - Console.WriteLine("IOException source: {0}", e.Source); + throw AssetException.CreateForProcessingError(e); } return this; @@ -401,7 +401,7 @@ public AssetLibrary Except(String[] fieldUids) } catch (Exception e) { - Console.WriteLine("IOException source: {0}", e.Source); + throw AssetException.CreateForProcessingError(e); } return this; } @@ -508,7 +508,7 @@ private async Task Exec() } catch (Exception ex) { - throw GetContentstackError(ex); + throw AssetException.CreateForProcessingError(ex); } } #endregion diff --git a/Contentstack.Core/Models/ContentType.cs b/Contentstack.Core/Models/ContentType.cs index bfd47a7..1baf39b 100644 --- a/Contentstack.Core/Models/ContentType.cs +++ b/Contentstack.Core/Models/ContentType.cs @@ -176,7 +176,7 @@ public async Task Fetch(Dictionary param = null) } catch (Exception ex) { - throw GetContentstackError(ex); + throw ContentTypeException.CreateForProcessingError(ex); } } diff --git a/Contentstack.Core/Models/Entry.cs b/Contentstack.Core/Models/Entry.cs index 1551a4b..a5c9ef8 100644 --- a/Contentstack.Core/Models/Entry.cs +++ b/Contentstack.Core/Models/Entry.cs @@ -510,7 +510,7 @@ public Entry SetLanguage(Language language) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } @@ -724,7 +724,7 @@ private Entry IncludeCreatedBy() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -801,7 +801,7 @@ private Entry IncludeUpdatedBy() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1094,7 +1094,7 @@ public Entry IncludeReferenceContentTypeUID() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1121,7 +1121,7 @@ public Entry IncludeFallback() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1149,7 +1149,7 @@ public Entry IncludeMetadata() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1177,7 +1177,7 @@ public Entry AddParam(string key, string value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1204,7 +1204,7 @@ public Entry IncludeBranch() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1231,7 +1231,7 @@ public Entry includeEmbeddedItems() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1259,7 +1259,7 @@ private Entry IncludeSchema() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1286,7 +1286,7 @@ public Entry IncludeOwner() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw EntryException.CreateForProcessingError(e); } return this; } @@ -1405,7 +1405,7 @@ public async Task Fetch() } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; } else { - throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + throw new LivePreviewException(); } if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId)) @@ -1446,7 +1446,7 @@ public async Task Fetch() } catch (Exception ex) { - throw GetContentstackError(ex); + throw EntryException.CreateForProcessingError(ex); } } diff --git a/Contentstack.Core/Models/GlobalField.cs b/Contentstack.Core/Models/GlobalField.cs index 3d8efd2..995cc4f 100644 --- a/Contentstack.Core/Models/GlobalField.cs +++ b/Contentstack.Core/Models/GlobalField.cs @@ -33,7 +33,7 @@ public string GlobalFieldId set { if (String.IsNullOrEmpty(value)) - throw new ArgumentNullException("GlobalFieldId cannot be null or empty."); + throw GlobalFieldException.CreateForIdNull(); this.Uid = value; } } @@ -189,7 +189,7 @@ public async Task Fetch(Dictionary param = null) } catch (Exception ex) { - throw GetContentstackError(ex); + throw GlobalFieldException.CreateForProcessingError(ex); } } diff --git a/Contentstack.Core/Models/GlobalFieldQuery.cs b/Contentstack.Core/Models/GlobalFieldQuery.cs index 270af47..b71cdc2 100644 --- a/Contentstack.Core/Models/GlobalFieldQuery.cs +++ b/Contentstack.Core/Models/GlobalFieldQuery.cs @@ -157,7 +157,7 @@ public async Task Find(Dictionary param = null) } catch (Exception ex) { - throw GetContentstackError(ex); + throw new ContentstackException(ErrorMessages.GlobalFieldQueryError, ex); } } diff --git a/Contentstack.Core/Models/Query.cs b/Contentstack.Core/Models/Query.cs index c50a09e..c80b29a 100644 --- a/Contentstack.Core/Models/Query.cs +++ b/Contentstack.Core/Models/Query.cs @@ -183,7 +183,7 @@ public Query SetLanguage(Language language) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } @@ -284,12 +284,12 @@ public Query Where(String key, Object value) } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; @@ -307,12 +307,12 @@ public Query ReferenceIn(String key, Query query) } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; @@ -330,12 +330,12 @@ public Query ReferenceNotIn(String key, Query query) } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; @@ -367,12 +367,12 @@ public Query AddQuery(String key, String value) } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -403,7 +403,7 @@ public Query RemoveQuery(String key) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -461,12 +461,12 @@ public Query And(List queryObjects) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -527,12 +527,12 @@ public Query Or(List queryObjects) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -571,12 +571,12 @@ public Query LessThan(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -615,12 +615,12 @@ public Query LessThanOrEqualTo(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; } @@ -658,12 +658,12 @@ public Query GreaterThan(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -702,12 +702,12 @@ public Query GreaterThanOrEqualTo(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -747,13 +747,13 @@ public Query NotEqualTo(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -797,12 +797,12 @@ public Query ContainedIn(String key, Object[] values) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -845,12 +845,12 @@ public Query NotContainedIn(String key, Object[] values) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -887,12 +887,12 @@ public Query Exists(String key) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -928,12 +928,12 @@ public Query NotExists(String key) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; @@ -962,7 +962,7 @@ public Query IncludeReferenceContentTypeUID() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1053,12 +1053,12 @@ private Query Tags(String[] tags) } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1089,12 +1089,12 @@ public Query Ascending(String key) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; } @@ -1125,12 +1125,12 @@ public Query Descending(String key) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; } @@ -1158,7 +1158,7 @@ public Query IncludeCount() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1187,7 +1187,7 @@ public Query IncludeMetadata() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1215,7 +1215,7 @@ public Query IncludeOwner() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1247,7 +1247,7 @@ public Query Only(String[] fieldUid) } catch (Exception e) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } return this; @@ -1316,7 +1316,7 @@ public Query Except(String[] fieldUids) } catch (Exception e) { - Console.WriteLine("IOException source: {0}", e.Source); + Console.WriteLine(ErrorMessages.FormatExceptionDetails(e)); } return this; } @@ -1378,7 +1378,7 @@ public Query IncludeFallback() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1406,7 +1406,7 @@ public Query IncludeBranch() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1434,7 +1434,7 @@ public Query AddParam(string key, string value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1462,7 +1462,7 @@ public Query includeEmbeddedItems() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1491,7 +1491,7 @@ public Query IncludeSchema() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1520,7 +1520,7 @@ public Query Skip(int number) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1549,7 +1549,7 @@ public Query Limit(int number) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return this; } @@ -1585,12 +1585,12 @@ public Query Regex(String key, String regex) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; } @@ -1634,12 +1634,12 @@ public Query Regex(String key, String regex, String modifiers) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw QueryFilterException.Create(); } return this; } @@ -1786,7 +1786,7 @@ public async Task Count() } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw QueryFilterException.Create(e); } return await Exec(); } @@ -1864,7 +1864,7 @@ private async Task Exec() } else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) { headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken; } else { - throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig"); + throw new LivePreviewException(); } if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.ReleaseId)) @@ -1948,7 +1948,7 @@ private async Task Exec() } catch (Exception ex) { - throw GetContentstackError(ex); + throw QueryFilterException.Create(ex); } } diff --git a/Contentstack.Core/Models/Taxonomy.cs b/Contentstack.Core/Models/Taxonomy.cs index f30dc13..a493251 100644 --- a/Contentstack.Core/Models/Taxonomy.cs +++ b/Contentstack.Core/Models/Taxonomy.cs @@ -73,12 +73,12 @@ public Taxonomy Above(String key, Object value) Dictionary queryValue = new Dictionary{ { "$above", value } }; QueryValueJson.Add(key, queryValue); } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw TaxonomyException.CreateForProcessingError(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw TaxonomyException.CreateForProcessingError(null); } return this; @@ -112,12 +112,12 @@ public Taxonomy EqualAndAbove(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw TaxonomyException.CreateForProcessingError(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw TaxonomyException.CreateForProcessingError(null); } return this; @@ -151,12 +151,12 @@ public Taxonomy Below(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw TaxonomyException.CreateForProcessingError(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw TaxonomyException.CreateForProcessingError(null); } return this; @@ -190,12 +190,12 @@ public Taxonomy EqualAndBelow(String key, Object value) } catch (Exception e) { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + throw TaxonomyException.CreateForProcessingError(e); } } else { - throw new Exception(StackConstants.ErrorMessage_QueryFilterException, null); + throw TaxonomyException.CreateForProcessingError(null); } return this;