@@ -138,6 +138,75 @@ public void RemoveHeader_RemovesHeader()
138138 }
139139
140140 #endregion
141+
142+ #region GetContentstackError Tests
143+
144+ [ Fact ]
145+ public void GetContentstackError_WithWebException_ReturnsContentstackException ( )
146+ {
147+ // Arrange
148+ var method = typeof ( GlobalField ) . GetMethod ( "GetContentstackError" ,
149+ BindingFlags . NonPublic | BindingFlags . Static ) ;
150+ var webEx = new System . Net . WebException ( "Test error" ) ;
151+
152+ // Act
153+ var result = method ? . Invoke ( null , new object [ ] { webEx } ) as Contentstack . Core . Internals . ContentstackException ;
154+
155+ // Assert
156+ Assert . NotNull ( result ) ;
157+ }
158+
159+ [ Fact ]
160+ public void GetContentstackError_WithGenericException_ReturnsContentstackException ( )
161+ {
162+ // Arrange
163+ var method = typeof ( GlobalField ) . GetMethod ( "GetContentstackError" ,
164+ BindingFlags . NonPublic | BindingFlags . Static ) ;
165+ var ex = new Exception ( "Test error" ) ;
166+
167+ // Act
168+ var result = method ? . Invoke ( null , new object [ ] { ex } ) as Contentstack . Core . Internals . ContentstackException ;
169+
170+ // Assert
171+ Assert . NotNull ( result ) ;
172+ Assert . Equal ( "Test error" , result . Message ) ;
173+ }
174+
175+ [ Fact ]
176+ public void GetContentstackError_WithWebException_HandlesExceptionCorrectly ( )
177+ {
178+ // Arrange
179+ var method = typeof ( GlobalField ) . GetMethod ( "GetContentstackError" ,
180+ BindingFlags . NonPublic | BindingFlags . Static ) ;
181+ var webEx = new System . Net . WebException ( "Test error" ) ;
182+
183+ // Act
184+ var result = method ? . Invoke ( null , new object [ ] { webEx } ) as Contentstack . Core . Internals . ContentstackException ;
185+
186+ // Assert
187+ Assert . NotNull ( result ) ;
188+ // When WebException has no response, it should fall back to ex.Message
189+ Assert . NotNull ( result . Message ) ;
190+ }
191+
192+ [ Fact ]
193+ public void ErrorHandling_WithWebException_ExtractsErrorMessage ( )
194+ {
195+ // Arrange
196+ var method = typeof ( GlobalField ) . GetMethod ( "GetContentstackError" ,
197+ BindingFlags . NonPublic | BindingFlags . Static ) ;
198+ var errorMessage = "Global field error" ;
199+ var ex = new Exception ( errorMessage ) ;
200+
201+ // Act
202+ var result = method ? . Invoke ( null , new object [ ] { ex } ) as Contentstack . Core . Internals . ContentstackException ;
203+
204+ // Assert
205+ Assert . NotNull ( result ) ;
206+ Assert . Equal ( errorMessage , result . Message ) ;
207+ }
208+
209+ #endregion
141210 }
142211}
143212
0 commit comments