Skip to content

Commit 1e333f7

Browse files
committed
Document ResponseException and derived types
1 parent 1ef8e09 commit 1e333f7

9 files changed

+285
-22
lines changed

src/corelib/Core/Exceptions/Response/BadServiceRequestException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.BadRequest"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class BadServiceRequestException : ResponseException
914
{
10-
public BadServiceRequestException(RestResponse response) : base("Unable to process the service request. Please try again later.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="BadServiceRequestException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public BadServiceRequestException(RestResponse response)
21+
: base("Unable to process the service request. Please try again later.", response)
22+
{
23+
}
1124

12-
public BadServiceRequestException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="BadServiceRequestException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public BadServiceRequestException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="BadServiceRequestException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected BadServiceRequestException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

src/corelib/Core/Exceptions/Response/ItemNotFoundException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.NotFound"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class ItemNotFoundException : ResponseException
914
{
10-
public ItemNotFoundException(RestResponse response) : base("The item was not found or does not exist.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ItemNotFoundException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public ItemNotFoundException(RestResponse response)
21+
: base("The item was not found or does not exist.", response)
22+
{
23+
}
1124

12-
public ItemNotFoundException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ItemNotFoundException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public ItemNotFoundException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ItemNotFoundException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected ItemNotFoundException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

src/corelib/Core/Exceptions/Response/MethodNotImplementedException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.NotImplemented"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class MethodNotImplementedException : ResponseException
914
{
10-
public MethodNotImplementedException(RestResponse response) : base("The requested method is not implemented at the service.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="MethodNotImplementedException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public MethodNotImplementedException(RestResponse response)
21+
: base("The requested method is not implemented at the service.", response)
22+
{
23+
}
1124

12-
public MethodNotImplementedException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="MethodNotImplementedException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public MethodNotImplementedException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="MethodNotImplementedException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected MethodNotImplementedException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

src/corelib/Core/Exceptions/Response/ResponseException.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,28 @@
66

77
namespace net.openstack.Core.Exceptions.Response
88
{
9+
/// <summary>
10+
/// Represents errors resulting from a call to a REST API.
11+
/// </summary>
912
[Serializable]
10-
public class ResponseException : Exception
13+
public abstract class ResponseException : Exception
1114
{
12-
public RestResponse Response { get; private set; }
15+
/// <summary>
16+
/// Gets the REST <see cref="RestResponse"/> containing the details
17+
/// about this error.
18+
/// </summary>
19+
public RestResponse Response
20+
{
21+
get;
22+
private set;
23+
}
1324

25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ResponseException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
1431
public ResponseException(string message, RestResponse response)
1532
: base(message)
1633
{
@@ -97,25 +114,38 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex
97114
}
98115
}
99116

100-
[DataContract]
117+
[JsonObject(MemberSerialization.OptIn)]
101118
private sealed class ErrorDetails
102119
{
103-
[DataMember(Name = "code")]
120+
#pragma warning disable 649 // Field '{fieldname}' is never assigned to, and will always have its default value {0 | null}
121+
[JsonProperty("code")]
104122
public int Code;
105123

106-
[DataMember(Name = "message")]
124+
[JsonProperty("message")]
107125
public string Message;
108126

109-
[DataMember(Name = "details")]
127+
[JsonProperty("details")]
110128
public string Details;
129+
#pragma warning restore 649
111130
}
112131

132+
/// <summary>
133+
/// Initializes a new instance of the <see cref="ResponseException"/> class with
134+
/// serialized data.
135+
/// </summary>
136+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
137+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
138+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
113139
protected ResponseException(SerializationInfo info, StreamingContext context)
114140
: base(info, context)
115141
{
142+
if (info == null)
143+
throw new ArgumentNullException("info");
144+
116145
Response = (RestResponse)info.GetValue("Response", typeof(RestResponse));
117146
}
118147

148+
/// <inheritdoc/>
119149
[SecurityCritical]
120150
public override void GetObjectData(SerializationInfo info, StreamingContext context)
121151
{

src/corelib/Core/Exceptions/Response/ServiceConflictException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.Conflict"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class ServiceConflictException : ResponseException
914
{
10-
public ServiceConflictException(RestResponse response) : base("There was a conflict with the service. Entity may already exist.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ServiceConflictException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public ServiceConflictException(RestResponse response)
21+
: base("There was a conflict with the service. Entity may already exist.", response)
22+
{
23+
}
1124

12-
public ServiceConflictException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ServiceConflictException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public ServiceConflictException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ServiceConflictException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected ServiceConflictException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

src/corelib/Core/Exceptions/Response/ServiceFaultException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.InternalServerError"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class ServiceFaultException : ResponseException
914
{
10-
public ServiceFaultException(RestResponse response) : base("There was an unhandled error at the service endpoint. Please try again later.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ServiceFaultException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public ServiceFaultException(RestResponse response)
21+
: base("There was an unhandled error at the service endpoint. Please try again later.", response)
22+
{
23+
}
1124

12-
public ServiceFaultException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ServiceFaultException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public ServiceFaultException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ServiceFaultException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected ServiceFaultException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

src/corelib/Core/Exceptions/Response/ServiceLimitReachedException.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
using System;
2+
using System.Net;
23
using System.Runtime.Serialization;
34
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
45

56
namespace net.openstack.Core.Exceptions.Response
67
{
8+
/// <summary>
9+
/// Represents errors with status code <see cref="HttpStatusCode.RequestEntityTooLarge"/> resulting
10+
/// from a call to a REST API.
11+
/// </summary>
712
[Serializable]
813
public class ServiceLimitReachedException : ResponseException
914
{
10-
public ServiceLimitReachedException(RestResponse response) : base("The service rate limit has been reached. Either request a service limit increase or wait until the limit resets.", response) { }
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ServiceLimitReachedException"/> class with the
17+
/// specified REST response.
18+
/// </summary>
19+
/// <param name="response">The REST response.</param>
20+
public ServiceLimitReachedException(RestResponse response)
21+
: base("The service rate limit has been reached. Either request a service limit increase or wait until the limit resets.", response)
22+
{
23+
}
1124

12-
public ServiceLimitReachedException(string message, RestResponse response) : base(message, response) { }
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ServiceLimitReachedException"/> class with the
27+
/// specified error message and REST response.
28+
/// </summary>
29+
/// <param name="message">The message that describes the error.</param>
30+
/// <param name="response">The REST response.</param>
31+
public ServiceLimitReachedException(string message, RestResponse response)
32+
: base(message, response)
33+
{
34+
}
1335

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ServiceLimitReachedException"/> class with
38+
/// serialized data.
39+
/// </summary>
40+
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
41+
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
42+
/// <exception cref="ArgumentNullException">If <paramref name="info"/> is <c>null</c>.</exception>
1443
protected ServiceLimitReachedException(SerializationInfo info, StreamingContext context)
1544
: base(info, context)
1645
{

0 commit comments

Comments
 (0)