1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Net ;
4+
5+ namespace Contentstack . Core . Internals
6+ {
7+ /// <summary>
8+ /// Base exception class for all Contentstack exceptions
9+ /// </summary>
10+ public class ContentstackException : Exception
11+ {
12+ public int ErrorCode { get ; set ; }
13+ public HttpStatusCode StatusCode { get ; set ; }
14+ public Dictionary < string , object > Errors { get ; set ; }
15+
16+ public ContentstackException ( ) : base ( )
17+ {
18+ }
19+
20+ public ContentstackException ( string message ) : base ( message )
21+ {
22+ }
23+
24+ public ContentstackException ( string message , Exception innerException ) : base ( message , innerException )
25+ {
26+ }
27+
28+ public ContentstackException ( Exception ex ) : base ( ex . Message , ex )
29+ {
30+ }
31+ }
32+
33+ /// <summary>
34+ /// Exception thrown when there are issues with query filters or parameters
35+ /// </summary>
36+ public class QueryFilterException : ContentstackException
37+ {
38+ public QueryFilterException ( ) : base ( ErrorMessages . QueryFilterError )
39+ {
40+ }
41+
42+ public QueryFilterException ( string message ) : base ( message )
43+ {
44+ }
45+
46+ public QueryFilterException ( string message , Exception innerException ) : base ( message , innerException )
47+ {
48+ }
49+
50+ public static QueryFilterException Create ( Exception innerException = null )
51+ {
52+ return new QueryFilterException (
53+ string . Format ( ErrorMessages . InvalidParamsError ,
54+ innerException ? . Message ?? ErrorMessages . QueryFilterError ) ,
55+ innerException ) ;
56+ }
57+ }
58+
59+ /// <summary>
60+ /// Exception thrown when there are asset-related errors
61+ /// </summary>
62+ public class AssetException : ContentstackException
63+ {
64+ public AssetException ( string message ) : base ( message )
65+ {
66+ }
67+
68+ public AssetException ( string message , Exception innerException ) : base ( message , innerException )
69+ {
70+ }
71+
72+ public static AssetException CreateForJsonConversionError ( )
73+ {
74+ return new AssetException ( ErrorMessages . AssetJsonConversionError ) ;
75+ }
76+
77+ public static AssetException CreateForProcessingError ( Exception innerException )
78+ {
79+ return new AssetException (
80+ string . Format ( ErrorMessages . AssetProcessingError ,
81+ ErrorMessages . FormatExceptionDetails ( innerException ) ) ,
82+ innerException ) ;
83+ }
84+ }
85+
86+ /// <summary>
87+ /// Exception thrown when there are live preview-related errors
88+ /// </summary>
89+ public class LivePreviewException : ContentstackException
90+ {
91+ public LivePreviewException ( ) : base ( ErrorMessages . LivePreviewTokenMissing )
92+ {
93+ }
94+
95+ public LivePreviewException ( string message ) : base ( message )
96+ {
97+ }
98+
99+ public LivePreviewException ( string message , Exception innerException ) : base ( message , innerException )
100+ {
101+ }
102+ }
103+
104+ /// <summary>
105+ /// Exception thrown when there are global field-related errors
106+ /// </summary>
107+ public class GlobalFieldException : ContentstackException
108+ {
109+ public GlobalFieldException ( string message ) : base ( message )
110+ {
111+ }
112+
113+ public GlobalFieldException ( string message , Exception innerException ) : base ( message , innerException )
114+ {
115+ }
116+
117+ public static GlobalFieldException CreateForProcessingError ( Exception innerException )
118+ {
119+ return new GlobalFieldException (
120+ string . Format ( ErrorMessages . GlobalFieldProcessingError ,
121+ ErrorMessages . FormatExceptionDetails ( innerException ) ) ,
122+ innerException ) ;
123+ }
124+
125+ public static GlobalFieldException CreateForIdNull ( )
126+ {
127+ return new GlobalFieldException ( ErrorMessages . GlobalFieldIdNullError ) ;
128+ }
129+ }
130+
131+ /// <summary>
132+ /// Exception thrown when there are entry-related errors
133+ /// </summary>
134+ public class EntryException : ContentstackException
135+ {
136+ public EntryException ( string message ) : base ( message )
137+ {
138+ }
139+
140+ public EntryException ( string message , Exception innerException ) : base ( message , innerException )
141+ {
142+ }
143+
144+ public static EntryException CreateForProcessingError ( Exception innerException )
145+ {
146+ return new EntryException (
147+ string . Format ( ErrorMessages . EntryProcessingError ,
148+ ErrorMessages . FormatExceptionDetails ( innerException ) ) ,
149+ innerException ) ;
150+ }
151+ }
152+ }
0 commit comments