11using System ;
22using System . IO ;
33using System . Net ;
4+ using System . Runtime . Serialization ;
5+ using System . Security . Permissions ;
46
57namespace Elasticsearch . Net . Connection
68{
9+ [ Serializable ]
710 public abstract class ElasticsearchAuthException : Exception
811 {
912 protected abstract string ExceptionType { get ; }
1013 protected abstract int StatusCode { get ; }
1114
15+ public ElasticsearchResponse < Stream > Response { get ; private set ; }
16+
1217 protected ElasticsearchAuthException ( ElasticsearchResponse < Stream > response )
1318 {
1419 this . Response = response ;
1520 }
1621
17- internal ElasticsearchServerException ToElasticsearchServerException ( )
18- {
19- if ( this . Response == null )
20- return null ;
21- return new ElasticsearchServerException ( this . StatusCode , this . ExceptionType ) ;
22- }
23- public ElasticsearchResponse < Stream > Response { get ; private set ; }
22+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
23+ protected ElasticsearchAuthException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
24+ {
25+ }
26+
27+ internal ElasticsearchServerException ToElasticsearchServerException ( ) =>
28+ this . Response == null ? null : new ElasticsearchServerException ( this . StatusCode , this . ExceptionType ) ;
29+
30+
2431 }
2532
33+ [ Serializable ]
2634 public class ElasticsearchAuthorizationException : ElasticsearchAuthException
2735 {
2836 public ElasticsearchAuthorizationException ( ElasticsearchResponse < Stream > response ) : base ( response ) { }
2937
30- protected override string ExceptionType { get { return "AuthorizationException" ; } }
38+ protected override string ExceptionType => "AuthorizationException" ;
39+
40+ protected override int StatusCode => 403 ;
41+
42+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
43+ protected ElasticsearchAuthorizationException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
44+ {
45+ }
46+
47+ [ SecurityPermissionAttribute ( SecurityAction . Demand , SerializationFormatter = true ) ]
48+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
49+ {
50+ if ( info == null ) throw new ArgumentNullException ( nameof ( info ) ) ;
3151
32- protected override int StatusCode { get { return 403 ; } }
52+ info . AddValue ( "ExceptionType" , this . ExceptionType ) ;
53+ info . AddValue ( "StatusCode" , this . StatusCode ) ;
54+ base . GetObjectData ( info , context ) ;
55+ }
3356 }
3457
3558
59+ [ Serializable ]
3660 public class ElasticsearchAuthenticationException : ElasticsearchAuthException
3761 {
38- protected override string ExceptionType { get { return "AuthenticationException" ; } }
62+ protected override string ExceptionType => "AuthenticationException" ;
3963
40- protected override int StatusCode { get { return 401 ; } }
64+ protected override int StatusCode => 401 ;
4165
4266 public ElasticsearchAuthenticationException ( ElasticsearchResponse < Stream > response ) : base ( response ) { }
4367
68+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
69+ protected ElasticsearchAuthenticationException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
70+ {
71+ }
72+
73+ [ SecurityPermissionAttribute ( SecurityAction . Demand , SerializationFormatter = true ) ]
74+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
75+ {
76+ if ( info == null ) throw new ArgumentNullException ( nameof ( info ) ) ;
77+
78+ info . AddValue ( "ExceptionType" , this . ExceptionType ) ;
79+ info . AddValue ( "StatusCode" , this . StatusCode ) ;
80+ base . GetObjectData ( info , context ) ;
81+ }
82+
4483 }
4584}
0 commit comments