-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extend exception and expose execution errors (#2)
- Loading branch information
1 parent
a8096e4
commit 8c22311
Showing
5 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
29 changes: 1 addition & 28 deletions
29
src/LibSql.Http.Client/Exceptions/LibSqlHttpClientException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,7 @@ | ||
using LibSql.Http.Client.Response; | ||
|
||
namespace LibSql.Http.Client.Exceptions; | ||
|
||
/// <inheritdoc /> | ||
public class LibSqlClientException(string message, Exception? innerException = default) | ||
: Exception(message, innerException) | ||
{ | ||
private const string TabConstant = "\t"; | ||
|
||
/// <summary> | ||
/// Create exception using errors from pipeline request | ||
/// </summary> | ||
/// <param name="executionErrors">Errors from pipeline response</param> | ||
public LibSqlClientException(IReadOnlyCollection<ExecutionError> executionErrors) : this( | ||
FormatErrorMessage(executionErrors)) | ||
{ | ||
} | ||
|
||
private static string FormatErrorMessage(IReadOnlyCollection<ExecutionError> executionErrors) | ||
{ | ||
var joinedMessages = string.Join( | ||
Environment.NewLine, | ||
executionErrors.Select( | ||
(error, index) => | ||
{ | ||
var codePart = error.Code is null ? string.Empty : $"({error.Code}) "; | ||
|
||
return $"{TabConstant}[{index}]: {codePart}{error.Message}"; | ||
})); | ||
|
||
return $"[LibSqlPipelineError] The request failed.{Environment.NewLine}{joinedMessages}"; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/LibSql.Http.Client/Exceptions/LibSqlHttpClientExecutionException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using LibSql.Http.Client.Response; | ||
|
||
namespace LibSql.Http.Client.Exceptions; | ||
|
||
/// <inheritdoc /> | ||
public class LibSqlClientExecutionException : LibSqlClientException | ||
{ | ||
private const string TabConstant = "\t"; | ||
|
||
/// <summary> | ||
/// Create exception using errors from pipeline request | ||
/// </summary> | ||
/// <param name="executionErrors">Errors from pipeline response</param> | ||
public LibSqlClientExecutionException(IReadOnlyCollection<ExecutionError> executionErrors) : base( | ||
FormatErrorMessage(executionErrors)) | ||
{ | ||
ExecutionErrors = executionErrors; | ||
} | ||
|
||
/// <summary> | ||
/// Errors from pipeline response | ||
/// </summary> | ||
public IReadOnlyCollection<ExecutionError> ExecutionErrors { get; } | ||
|
||
/// <summary> | ||
/// First error from pipeline response | ||
/// </summary> | ||
public ExecutionError Error => ExecutionErrors.First(); | ||
|
||
private static string FormatErrorMessage(IReadOnlyCollection<ExecutionError> executionErrors) | ||
{ | ||
var joinedMessages = string.Join( | ||
Environment.NewLine, | ||
executionErrors.Select( | ||
(error, index) => | ||
{ | ||
var codePart = error.Code is null ? string.Empty : $"({error.Code}) "; | ||
|
||
return $"{TabConstant}[{index}]: {codePart}{error.Message}"; | ||
})); | ||
|
||
return $"[LibSqlPipelineError] The request failed.{Environment.NewLine}{joinedMessages}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters