Folks:
I’d like to test the .Net SDK handling of 429s, so I provided this as the base URL when creating the client:
https://httpstat.us/429/
This does not eventually result in the request throwing a SquareApiException
with StatusCode
== 429 as would reasonably be expected. It instead throws this:
System.Text.Json.JsonException: 'T' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: 0 | BytePositionInLine: 4. ---> System.Text.Json.JsonReaderException: 'T' is invalid after a single JSON value. Expected end of data. LineNumber: 0 | BytePositionInLine: 4.
...
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at Square.SquareApiException.BuildMessage(String message, Int32 statusCode, Object body, JsonElement& jsonElement)
at Square.SquareApiException..ctor(String message, Int32 statusCode, Object body)
at Square.Merchants.MerchantsClient.<ListInternalAsync>d__8.MoveNext()
It looks like the SquareApiException
constructor isn’t robust to “malformed” response payloads…
The httpstat.us
web page says:
To get a JSON response back, you need to ensure that the Accept header contains ‘application/json’. Then we’ll JSON encode the response and send the Content-Type header accordingly.
From the error it looks like the SDK API request isn’t including an Accept
header with application/json
. I’ve been unable to confirm this.
How would we test the 429 handling? Is there a dedicated Square API test endpoint somewhere that will always return predictable errors?
6 posts - 3 participants