1- namespace ResponseCrafter . HttpExceptions ;
1+ using System . Collections ;
2+ using System . Diagnostics . CodeAnalysis ;
23
3- public class ServiceUnavailableException ( string message = ServiceUnavailableException . DefaultMessage ) : ApiException ( 503 , message )
4+ namespace ResponseCrafter . HttpExceptions ;
5+
6+ public class ServiceUnavailableException ( string message = ServiceUnavailableException . DefaultMessage )
7+ : ApiException ( 503 , message )
48{
5- private const string DefaultMessage = "the_server_is_currently_unavailable._please_try_again_later." ;
9+ private const string DefaultMessage = "the_server_is_currently_unavailable._please_try_again_later." ;
10+
11+ public static void ThrowIfNull ( [ NotNull ] object ? value , string exceptionMessage )
12+ {
13+ if ( value is null )
14+ {
15+ throw new ServiceUnavailableException ( exceptionMessage ) ;
16+ }
17+ }
18+
19+ public static void ThrowIfNullOrEmpty ( [ NotNull ] IEnumerable ? value , string exceptionMessage )
20+ {
21+ // ReSharper disable once GenericEnumeratorNotDisposed
22+ if ( value is null || ! value . GetEnumerator ( )
23+ . MoveNext ( ) )
24+ {
25+ throw new ServiceUnavailableException ( exceptionMessage ) ;
26+ }
27+ }
28+
29+ public static void ThrowIfNullOrWhiteSpace ( [ NotNull ] string ? value , string exceptionMessage )
30+ {
31+ if ( string . IsNullOrWhiteSpace ( value ) )
32+ {
33+ throw new ServiceUnavailableException ( exceptionMessage ) ;
34+ }
35+ }
36+
37+
38+ public static void ThrowIf ( bool condition , string exceptionMessage )
39+ {
40+ if ( condition )
41+ {
42+ throw new ServiceUnavailableException ( exceptionMessage ) ;
43+ }
44+ }
45+
46+ public static void ThrowIfNullOrNegative ( [ NotNull ] decimal ? value , string exceptionMessage )
47+ {
48+ if ( value is < 0 or null )
49+ {
50+ throw new ServiceUnavailableException ( exceptionMessage ) ;
51+ }
52+ }
653}
0 commit comments