Skip to content

Commit

Permalink
(GH-367) Debugging code to help find SendGrid endpoints that return t…
Browse files Browse the repository at this point in the history
…he "Link" header
  • Loading branch information
Jericho committed Aug 4, 2024
1 parent 31538b9 commit d3e6e01
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Source/StrongGrid/Extensions/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ internal static string GetParameterValue(this MultipartFormDataParser parser, st
/// <exception cref="SendGridException">An error occurred processing the response.</exception>
internal static Task<T> AsObject<T>(this IResponse response, string propertyName = null, bool throwIfPropertyIsMissing = true, JsonSerializerOptions options = null)
{
#if DEBUG
// This is debugging code to help me figure out which SendGrid endpoints return paging information in the 'Link' response header
var link = response.Message.Headers.GetValue("Link");
if (!string.IsNullOrEmpty(link))
{
var verb = response.Message.RequestMessage.Method;
var path = response.Message.RequestMessage.RequestUri.AbsolutePath.Replace("/v3/", string.Empty);
var request = $"{verb} {path}";
throw new Exception($"The 'Link' header has been found in the response when making a request to: {request}");
}
#endif
return response.Message.Content.AsObject<T>(propertyName, throwIfPropertyIsMissing, options);
}

Expand All @@ -237,6 +248,17 @@ internal static async Task<T> AsObject<T>(this IRequest request, string property
/// <exception cref="SendGridException">An error occurred processing the response.</exception>
internal static Task<PaginatedResponse<T>> AsPaginatedResponse<T>(this IResponse response, string propertyName = null, JsonSerializerOptions options = null)
{
#if DEBUG
// This is debugging code to help me figure out which SendGrid endpoints return paging information in the 'Link' response header
var link = response.Message.Headers.GetValue("Link");
if (!string.IsNullOrEmpty(link))
{
var verb = response.Message.RequestMessage.Method;
var path = response.Message.RequestMessage.RequestUri.AbsolutePath.Replace("/v3/", string.Empty);
var request = $"{verb} {path}";
throw new Exception($"The 'Link' header has been found in the response when making a request to: {request}");
}
#endif
return response.Message.Content.AsPaginatedResponse<T>(propertyName, options);
}

Expand Down

0 comments on commit d3e6e01

Please sign in to comment.