Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
These days I needed the error code from the HttpClientCurlDelegate and could not get it (it was always 0) and that was because in the function execute of the HttpClientCurlDelegate the error code was not sent to the thrown HttpClientException.
I know that we can extend the classes and have this happen without this fix, but I believe it's more appropriate to have the correct functionality by default rather than needing to do 'extra work' for that.
I will provide the patch below.
Comment | File | Size | Author |
---|---|---|---|
#1 | http_client-send_error_code-2383119-1.patch | 853 bytes | lhangea |
Comments
Comment #1
lhangea CreditAttribution: lhangea commentedPatch for this issue
Comment #2
lhangea CreditAttribution: lhangea commentedComment #3
Bhanuji CreditAttribution: Bhanuji commentedComment #4
John Franklin CreditAttribution: John Franklin at Sentai Digital for Bixal commentedThat code is normally the HTTP response code (401, 403, 500), and not the errno from curl. IMHO, giving that error code two meanings is bad design.
There are three other places this Exception is thrown: when unserializing a response that is not well-formed; and twice in a long committed, but never released piece of code that is parsing the response from a proxy. In all those cases, the response code is left 0.
This is called in the delegate, which is not accessible to the code using
HttpClient
, so saving the errno won't work.The right thing to do is to throw a different exception, say
HttpClientCurlException
, with the curl error in it. We can make this Exception extend from theHttpCurlException
to maintain backwards compatibility and not require a major number bump.@lhangea, what do you think of this? It has been six years since you posted this patch. Does the site where you needed this still run Drupal 7?
Comment #5
John Franklin CreditAttribution: John Franklin at Sentai Digital for Bixal commentedMarking "Needs work" until we can figure out a better solution.