Comments (7)
@mateusduboli Hi Mateus!
Have you considered wrapping your callback function to catch + handle exceptions in your preferred way? If that's for some reason not possible or desirable, could you please explain why so that I can better understand your situation?
Thanks!
from http-kit.
A proposed solution, would be to use the
ContextLogger
from the client variable calculated just before the call.But Ideally these logs should comply with
slf4j
or some other interface that would allow for more fine grained control using configuration files.
ContextLogger
is an interface, so you can log to anything in the implementation. This eliminates 3rd party dependency.
from http-kit.
I think any place that uses a hardcoded reference to HttpUtils/printError is a candidate of this problem.
From what I can see there, http-kit appears to only use printError
in 2 cases where the user is in control of the function that could throw.
I.e. the design appears to be that these printError
s occur only in exceptional circumstances, and as a fallback when the user hasn't provided their own error handling.
That seems generally reasonable to me, given that custom error handling is fundamentally a superset of custom error logging.
Though I understand that in your case, the library you're using seems to be obscuring access to custom error handling.
Assuming there's no way of providing a custom handler in Martian, it seems the options are:
- Provide a PR for http-kit to allow custom error logging
- Advocate for an enhancement to Martian (if applicable) to allow custom error handling, since I suspect that might be useful in general (?)
The two aren't mutually exclusive, and both could be independently worthwhile.
Would be happy to take a look at a PR for (1.) if you like.
Cheers :-)
from http-kit.
from http-kit.
There are options to resolve it, like not using exceptions as a control
flow
Could you please expand on this? Where are exceptions being used as control flow?
however it still feel that the library does not provide enough
flexibility to for instance send these exceptions to a file.
By "the library", do you mean http-kit or Martian?
If http-kit: is there some other place (besides the client request callback) where you want to control the behaviour on errors and cannot?
from http-kit.
Could you please expand on this? Where are exceptions being used as control flow?
This is being used in my application, where when the status code is above 400 it will wrap the response in an exception, this exception is used on my "handler" code to perform decisions.
(require '[org.httpkit.client :as http])
(defn process-response [{status :status :as response}]
(if (>= status 400)
(throw (ex-info "Error in response" {:response response}))
response))
@(http/request {:method :get
:url "http://httpstat.us/400"}
process-response)
This code both returns the exception and prints it on stderr
, in my case the process-response
is wrapped by another function would be something like:
(defn safe-process-response [response]
(try
(process-response response)
(catch Throwable t
(log-and-suppress-error t))
The problem is, IF I don't have access to the code that manages these callbacks, I cannot suppress the exception going to the stderr
, which I could do for other logs in httpkit
by binding the org.httpkit.client/*default-client*
.
By "the library", do you mean http-kit or Martian?
I mean http-kit
, as these logs are managed by it.
If http-kit: is there some other place (besides the client request callback) where you want to control the behaviour on errors and cannot?
I think any place that uses a hardcoded reference to HttpUtils/printError
is a candidate of this problem.
https://github.com/search?q=repo%3Ahttp-kit/http-kit%20printError&type=code
from http-kit.
Studying the code I wanted to double check some understandings that I have about org.httpkit.client/request and its relation to HttpClient.
- HttpClient runs as a single background thread that takes requests and enqueues then, doing a busy loop to find the next request to execute or to process it's response.
- To get the response, still on java land, an implementation of the
IRespListener
interface is the one responsible to decode and process the communication. - That interface will send the parsed body, headers and status to a new instance of
IRespHandler
, that handler will be executed on a different ThreadPool, namely theworker-pool
- The interaction between the java and the clojure is made through the implementation of
IRespListener
andIRespHandler
. - For handling asynchronous requests a
promise
is used to hold the value, and thedeliver
call that wraps all the results for the reyfied IRespHandler. - The
callback
runs on theworker-pool
thread-pool as it is done on theIRespHandler
.
What I'm trying to organize is the relation between the callback
and the HttpClient
to be able to make use of the existing configured loggers.
However, because they are executed in different thread-pools and in contexts which the HttpClient
is not a dependency it seems not to be possible.
From that, it seems the simplest solution would be to add a error-logger
parameter to the request
call, or to use a *error-logger*
global, this will NOT resolve the problem of other instances of HttpUtils.printError
, such as TimerService.
Do you see any other ideas?
from http-kit.
Related Issues (20)
- CURL and finagle failing to parse :set-cookies with '\n' HOT 13
- Unix socket benchmark HOT 1
- It will turn headers into camel format HOT 2
- logger-warn gets rebound HOT 1
- logger-warn and error-warn are passed in wrong order to HttpServer constructor HOT 1
- Requests which throw java.net.ConnectException may actually succeed HOT 3
- Request Map doesn't contain information about authority HOT 8
- http-kit v2.8.0-RC1 HOT 1
- http-kit v2.8.0 final HOT 1
- Consider adding `Content-Type: text/plain` to HTTP 500 response in `org.httpkit.server.HttpHandler#run` HOT 6
- v2.7.0 SNI change broke connections to plain IP addresses with SSLHandshakeException "Hostname or IP address is undefined." HOT 8
- Add options for encoding nested form and query params a la clj-http HOT 7
- WebTransport support HOT 2
- NoSuchMethodError on projects AOT'd on java 21 but run on earlier java versions HOT 13
- [Proposal][Client] Consider more idiomatic bridges with JVM async paradigms HOT 5
- "Unmasked client to server frame" causes 502s HOT 9
- [client][performance] Regression after #446 HOT 3
- Add updated WebSocket examples to Wiki HOT 3
- documentation needs cleaning up and centralizing (was -> footnote link for API docs / run-server is wrong) HOT 2
- Possible native memory leak HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-kit.