Skip to content

Commit 2e28d77

Browse files
committed
Store 'Reason' on it's own property and pass the original exception as the inner exception
1 parent 8f7a062 commit 2e28d77

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

src/CouchDB.Driver/Exceptions/CouchConflictException.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
namespace CouchDB.Driver.Exceptions
1+
using CouchDB.Driver.DTOs;
2+
using System;
3+
4+
namespace CouchDB.Driver.Exceptions
25
{
36
/// <summary>
47
/// The exception that is thrown when there is a conflict.
58
/// </summary>
69
public class CouchConflictException : CouchException
710
{
8-
/// <summary>
9-
/// Creates a new instance of CouchConflictException.
10-
/// </summary>
11-
/// <param name="message">Error message</param>
12-
/// <param name="reason">Error reason</param>
13-
public CouchConflictException(string message, string reason) : base(message, reason) { }
11+
internal CouchConflictException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }
1412

1513
public CouchConflictException()
1614
{
@@ -20,7 +18,7 @@ public CouchConflictException(string message) : base(message)
2018
{
2119
}
2220

23-
public CouchConflictException(string message, System.Exception innerException) : base(message, innerException)
21+
public CouchConflictException(string message, Exception innerException) : base(message, innerException)
2422
{
2523
}
2624
}

src/CouchDB.Driver/Exceptions/CouchException.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using CouchDB.Driver.DTOs;
2+
using System;
23

34
namespace CouchDB.Driver.Exceptions
45
{
@@ -12,18 +13,31 @@ public class CouchException : Exception
1213
/// </summary>
1314
/// <param name="message">Error message</param>
1415
/// <param name="reason">Error reason</param>
15-
public CouchException(string message, string reason) : base(message, new Exception(reason)) { }
16+
public CouchException(string message, string reason) : this(message, reason, null)
17+
{
18+
}
19+
20+
public CouchException() : this(null, null, null)
21+
{
22+
}
1623

17-
public CouchException()
24+
public CouchException(string message) : this(message, null, null)
1825
{
1926
}
2027

21-
public CouchException(string message) : base(message)
28+
public CouchException(string message, Exception innerException) : this(message, null, innerException)
2229
{
2330
}
2431

25-
public CouchException(string message, Exception innerException) : base(message, innerException)
32+
internal CouchException(CouchError couchError, Exception innerException) : this(couchError?.Error, couchError?.Reason, innerException)
2633
{
2734
}
35+
36+
public CouchException(string message, string reason, Exception innerException) : base(message, innerException)
37+
{
38+
Reason = reason;
39+
}
40+
41+
public string Reason { get; }
2842
}
2943
}

src/CouchDB.Driver/Exceptions/CouchNoIndexException.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
namespace CouchDB.Driver.Exceptions
1+
using CouchDB.Driver.DTOs;
2+
using System;
3+
4+
namespace CouchDB.Driver.Exceptions
25
{
36
/// <summary>
47
/// The exception that is thrown when there is no index for the query.
58
/// </summary>
69
public class CouchNoIndexException : CouchException
710
{
8-
/// <summary>
9-
/// Creates a new instance of CouchNoIndexException.
10-
/// </summary>
11-
/// <param name="message">Error message</param>
12-
/// <param name="reason">Error reason</param>
13-
public CouchNoIndexException(string message, string reason) : base(message, reason) { }
11+
internal CouchNoIndexException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }
1412

1513
public CouchNoIndexException()
1614
{
@@ -20,7 +18,7 @@ public CouchNoIndexException(string message) : base(message)
2018
{
2119
}
2220

23-
public CouchNoIndexException(string message, System.Exception innerException) : base(message, innerException)
21+
public CouchNoIndexException(string message, Exception innerException) : base(message, innerException)
2422
{
2523
}
2624
}

src/CouchDB.Driver/Exceptions/CouchNotFoundException.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
namespace CouchDB.Driver.Exceptions
1+
using CouchDB.Driver.DTOs;
2+
using System;
3+
4+
namespace CouchDB.Driver.Exceptions
25
{
36
/// <summary>
47
/// The exception that is thrown when something is not found.
58
/// </summary>
69
public class CouchNotFoundException : CouchException
710
{
8-
/// <summary>
9-
/// Creates a new instance of CouchNotFoundException.
10-
/// </summary>
11-
/// <param name="message">Error message</param>
12-
/// <param name="reason">Error reason</param>
13-
public CouchNotFoundException(string message, string reason) : base(message, reason) { }
11+
internal CouchNotFoundException(CouchError couchError, Exception innerException) : base(couchError, innerException) { }
1412

1513
public CouchNotFoundException()
1614
{
@@ -20,7 +18,7 @@ public CouchNotFoundException(string message) : base(message)
2018
{
2119
}
2220

23-
public CouchNotFoundException(string message, System.Exception innerException) : base(message, innerException)
21+
public CouchNotFoundException(string message, Exception innerException) : base(message, innerException)
2422
{
2523
}
2624
}

src/CouchDB.Driver/Helpers/RequestsHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public static async Task<T> SendRequestAsync<T>(this Task<T> asyncRequest)
3333
switch (ex.Call.HttpStatus)
3434
{
3535
case HttpStatusCode.Conflict:
36-
throw couchError.NewCouchExteption(typeof(CouchConflictException));
36+
throw new CouchConflictException(couchError, ex);
3737
case HttpStatusCode.NotFound:
38-
throw couchError.NewCouchExteption(typeof(CouchNotFoundException));
38+
throw new CouchNotFoundException(couchError, ex);
3939
case HttpStatusCode.BadRequest when couchError.Error == "no_usable_index":
40-
throw couchError.NewCouchExteption(typeof(CouchNoIndexException));
40+
throw new CouchNoIndexException(couchError, ex);
4141
default:
42-
throw new CouchException(couchError.Error, couchError.Reason);
42+
throw new CouchException(couchError, ex);
4343
}
4444
}
4545
}

0 commit comments

Comments
 (0)