haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Usability Improvements to sys.Http

Open c-g-dev opened this issue 9 months ago • 0 comments

1) Change onError to actually return the HTTP error

Currently onError() only sends application-specific semantic errors (e.g. "Http status: #400" which is hardcoded as a thrown exception). This eats all error information sent by the client explaining the error. For example, the server might return "missing parameter" information with their 400 response, but there is no way to access that information from sys.Http because the class only returns its own errors.

I believe that the following small change would fix the issue:


//in sys.Http

	public override function request(?post:Bool) {
		var output = new haxe.io.BytesOutput();
		var old = onError;
		var err = false;
		onError = function(e) {
			responseBytes = output.getBytes();
			err = true;
			onError = old;
			onError(e); //TODO: change this to something like onError(responseBytes.toString()); or onError(e + " : " + responseBytes.toString());
		}
		post = post || postBytes != null || postData != null;
		customRequest(post, output);
		if (!err) {
			success(output.getBytes());
		}
	}

2) Increase default cnxTimeout AND/OR give Sockets better error message on timeout

Current default timeout for Sockets is 10 seconds which is actually extremely likely to be hit for many applications. Sure, this is directly configurable, but a) I don't see any reason why the default timeout should be this short length and b) if the socket does time out the http.request() just throws a meaningless "Blocked" error which doesn't actually indicate that there was a timeout or tell the user that they need to increase cnxTimeout.

c-g-dev avatar Jul 09 '25 17:07 c-g-dev