[fpc-devel] Avoid exception if FPHTTPClient cannot connect to server?
Karoly Balogh (Charlie/SGR)
charlie at scenergy.dfmk.hu
Mon Jul 31 14:04:59 CEST 2017
Hi,
On Mon, 31 Jul 2017, Werner Pamler wrote:
> If the URL exists everything is fine (note on Windows, that the OpenSSL
> dlls must be copied to the exe directory for the demo to work). If the
> URL does not exist, but the server responds, the program returns the
> well-known error 404 (if the 404 has been added to the response codes in
> HTTPMethod) - also fine. But if a connection to the server cannot be
> established -- maybe because the server URL is wrong -- then the program
> creates an exception. Synapse, on the other hand, does not crash on this
> occasion, it just returns an error 500. This behavior appears to be much
> more consistent than fpc's.
I disagree. I think generating any HTTP error code locally, which should
always come from the server is anything but a good idea. It could mask
true server issues from network connectivity issues, which distinction
could be still relevant and the client application might want to employ
different error mitigation techniques to solve one or the other case.
> Is this intentional? Or should I report a bug?
The code in FPHTTPClient has an explicit Raise line when the connection is
unsuccessful. So I'd say this is not a bug, but by design. Maybe this
behavior should be better documented or the Exception itself could be more
descriptive tho', but I haven't tried this.
(Note that I generally dislike APIs which are designed to throw
exceptions, but anyway, in this case it looks like it's by design and it's
still better than just generating a random HTTP code locally.)
Charlie
More information about the fpc-devel
mailing list