From d3e6e01e438c6b0b64bf53bdec52f9c08cca2efa Mon Sep 17 00:00:00 2001 From: Jericho Date: Sun, 24 Jan 2021 16:39:20 -0500 Subject: [PATCH] (GH-367) Debugging code to help find SendGrid endpoints that return the "Link" header --- Source/StrongGrid/Extensions/Internal.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/StrongGrid/Extensions/Internal.cs b/Source/StrongGrid/Extensions/Internal.cs index b06af59b..41b93360 100644 --- a/Source/StrongGrid/Extensions/Internal.cs +++ b/Source/StrongGrid/Extensions/Internal.cs @@ -211,6 +211,17 @@ internal static string GetParameterValue(this MultipartFormDataParser parser, st /// An error occurred processing the response. internal static Task AsObject(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(propertyName, throwIfPropertyIsMissing, options); } @@ -237,6 +248,17 @@ internal static async Task AsObject(this IRequest request, string property /// An error occurred processing the response. internal static Task> AsPaginatedResponse(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(propertyName, options); }