-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
245 additions
and
268 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// Represents a <see cref="DelegatingHandler"/> that treats responses as | ||
/// having been sent by Firecrawl. | ||
/// </summary> | ||
public sealed class FirecrawlDelegatingHandler : | ||
DelegatingHandler | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the | ||
/// <see cref="FirecrawlDelegatingHandler"/> class. | ||
/// </summary> | ||
public FirecrawlDelegatingHandler() : | ||
base() | ||
{ } | ||
|
||
/// <inheritdoc/> | ||
protected override async Task<HttpResponseMessage> SendAsync( | ||
HttpRequestMessage request, | ||
CancellationToken cancellationToken) | ||
{ | ||
var httpClientResponse = | ||
default(HttpResponseMessage); | ||
|
||
try | ||
{ | ||
httpClientResponse = | ||
await base.SendAsync( | ||
request, | ||
cancellationToken); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new FirecrawlException( | ||
"The operation was not successful.", | ||
ex); | ||
} | ||
|
||
if (httpClientResponse.StatusCode != HttpStatusCode.OK) | ||
{ | ||
var error = | ||
await httpClientResponse.Content | ||
.ReadFromJsonAsync<FirecrawlError>( | ||
FirecrawlService.JsonSerializerOptions, | ||
cancellationToken); | ||
|
||
throw new FirecrawlException( | ||
"The operation was not successful.", | ||
default, | ||
httpClientResponse.StatusCode, | ||
error); | ||
} | ||
|
||
return httpClientResponse; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,163 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
|
||
namespace Firecrawl | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class FirecrawlException : | ||
Exception | ||
HttpRequestException | ||
{ | ||
#if NETSTANDARD | ||
|
||
/// <summary> | ||
/// | ||
/// Gets the HTTP status code for this exception, if any. | ||
/// </summary> | ||
public HttpStatusCode? StatusCode { get; private init; } | ||
|
||
#endif | ||
|
||
/// <summary> | ||
/// Gets the Firecrawl error for this exception, if any. | ||
/// </summary> | ||
public FirecrawlError Error { get; private init; } | ||
|
||
/// <summary> | ||
/// | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class. | ||
/// </summary> | ||
public FirecrawlException() : | ||
this( | ||
default) | ||
{ } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class with a specific message that describes the current exception. | ||
/// </summary> | ||
/// <param name="message"> | ||
/// A message that describes the current exception. | ||
/// </param> | ||
public FirecrawlException( | ||
string message) : | ||
this( | ||
message, | ||
default) | ||
{ } | ||
|
||
/// <summary> | ||
/// | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class with a specific message that describes the current exception | ||
/// and an inner exception. | ||
/// </summary> | ||
/// <param name="statusCode"></param> | ||
/// <param name="message"> | ||
/// A message that describes the current exception. | ||
/// </param> | ||
/// <param name="innerException"> | ||
/// The inner exception. | ||
/// </param> | ||
public FirecrawlException( | ||
HttpStatusCode statusCode) : | ||
string message, | ||
Exception innerException) : | ||
this( | ||
statusCode, | ||
message, | ||
innerException, | ||
default) | ||
{ } | ||
|
||
/// <summary> | ||
/// | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class with a specific message that describes the current exception, | ||
/// an inner exception, and an HTTP status code. | ||
/// </summary> | ||
/// <param name="statusCode"></param> | ||
/// <param name="message"></param> | ||
/// <param name="message"> | ||
/// A message that describes the current exception. | ||
/// </param> | ||
/// <param name="innerException"> | ||
/// The inner exception. | ||
/// </param> | ||
/// <param name="statusCode"> | ||
/// The HTTP status code. | ||
/// </param> | ||
public FirecrawlException( | ||
HttpStatusCode statusCode, | ||
string message) : | ||
string message, | ||
Exception innerException, | ||
HttpStatusCode? statusCode) : | ||
this( | ||
statusCode, | ||
message, | ||
innerException, | ||
statusCode, | ||
default) | ||
{ } | ||
|
||
#if NETSTANDARD | ||
|
||
/// <summary> | ||
/// | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class with a specific message that describes the current exception, | ||
/// an inner exception, an HTTP status code, and Firecrawl error. | ||
/// </summary> | ||
/// <param name="statusCode"></param> | ||
/// <param name="message"></param> | ||
/// <param name="innerException"></param> | ||
/// <param name="message"> | ||
/// A message that describes the current exception. | ||
/// </param> | ||
/// <param name="innerException"> | ||
/// The inner exception. | ||
/// </param> | ||
/// <param name="statusCode"> | ||
/// The HTTP status code. | ||
/// </param> | ||
/// <param name="error"> | ||
/// The Firecrawl error. | ||
/// </param> | ||
public FirecrawlException( | ||
HttpStatusCode statusCode, | ||
string message, | ||
Exception innerException) : | ||
Exception innerException, | ||
HttpStatusCode? statusCode, | ||
FirecrawlError error) : | ||
base( | ||
message, | ||
innerException) | ||
{ | ||
StatusCode = statusCode; | ||
Error = error; | ||
} | ||
|
||
#endif | ||
|
||
#if NET | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FirecrawlException"/> | ||
/// class with a specific message that describes the current exception, | ||
/// an inner exception, an HTTP status code, and Firecrawl error. | ||
/// </summary> | ||
/// <param name="message"> | ||
/// A message that describes the current exception. | ||
/// </param> | ||
/// <param name="innerException"> | ||
/// The inner exception. | ||
/// </param> | ||
/// <param name="statusCode"> | ||
/// The HTTP status code. | ||
/// </param> | ||
/// <param name="error"> | ||
/// The Firecrawl error. | ||
/// </param> | ||
public FirecrawlException( | ||
string message, | ||
Exception innerException, | ||
HttpStatusCode? statusCode, | ||
FirecrawlError error) : | ||
base( | ||
message, | ||
innerException, | ||
statusCode) | ||
{ | ||
Error = error; | ||
} | ||
|
||
#endif | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,6 @@ namespace Firecrawl | |
/// </summary> | ||
public class FirecrawlResult | ||
{ | ||
|
||
// This space intentionally left blank. | ||
} | ||
} |
Oops, something went wrong.