-
Notifications
You must be signed in to change notification settings - Fork 447
Internet API Throws Exception for HTTP Error Response (again) #3663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For now I was able to circumvent the problem with a pretty ugly solution. I parse the response in a protected call, and if I get an error, I use string.match() to find the error code within the error message. Unfortunately the error message changes for codes 404 and 410, leaving no information on which of those two error codes was received. Since 404 is way more frequent, I decided to return 404 in that situation. Of course a fix would be better.
|
It was fixed, but then it was reverted as not every Minecraft configuration actually had the Apache HTTP client library, nor could I figure out in the limited maintenance time I have for the mod: 555ae0e |
The problem, I suppose, is that:
So this would best go into an OpenComputers 1.9.0 update; but given the mod is essentially unmaintained... |
@kodai2199 Hopefully this workaround will be to your satisfaction, for the time being. |
… reading unsuccessful HTTP responses' output,
Bug Fix Summary for Issue #3708 #3663 Root Cause Solution After (fixed code): Key Changes
Result
Testing
|
Previously, HTTP error responses (4xx, 5xx) would throw exceptions instead of allowing access to response information. This made it impossible to handle API errors gracefully in Lua scripts. Changes: - Capture response code/message/headers before attempting to read stream - Use getErrorStream() for HTTP error responses instead of getInputStream() - Provide empty stream fallback when getErrorStream() returns null - Preserve existing behavior for successful responses (2xx) This allows scripts to check response codes and read error response bodies using the existing response() and read() methods. Fixes MightyPirates#3663
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to use a REST API I built, but I cannot handle HTTP error codes in-game, because attempting to iterate over the request handle throws the following error: Server returned HTTP response code: 400 for URL: ..., and getmetatable(handle).__index.response() simply returns nil so I am unable to check for certain response codes there either.
I believe this issue was said to be fixed here #3398. However, in the latest version, this bug is still here. I am tempted to look at the differences between the relevant files in the latest release and in the older ones to see what's going on.
I am now using https://http.codes/ for testing purposes, and I can confirm that I can correctly get codes for responses like 200 OK. But with 400, 404, ... I only get nil, and an error if I try to read the response.
Thank you in advance for your support!
The text was updated successfully, but these errors were encountered: