-
Notifications
You must be signed in to change notification settings - Fork 165
Capture error message, otherwise capture cause of HTTP failure #358
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
Conversation
Not sure if this codebase favors |
This fix seems like a reasonable simple iteration to me. I tried it with import Nano from './lib/nano.js'
const nano = Nano('http://localhost:9999')
async function main() {
await nano.db.list()
}
main() Works fine (in that you get an error with a sensible error message) in Node, but a reproducer of your problem when using bun. It seems to come down do different formats of responses in Node & Bun. Your |
I tried to run the tests in |
Thanks @glynnbird; I also reproduced the fix with ![]() Showed the before and after there. Proud to bring a commit to this awesome repository once merged! |
if you remove "WIP" and request a review from me I can get it moving. |
Actually if we go with:
then Node errors always get "fetch failed" which is not a great error message, not as good as what about response.cause ? response.cause.toString() : response.message instead? I reckon most users are Node users anyway? |
Removed In the hypothetical, there is the possibility that In this approach: response.statusText = response.message ?? response.cause?.toString() I have tried to move away from Looking ahead 10 years: This is almost to the point of being able to use The underlying question regarding What is best for us? I tend to think fast code without any possibility of an error due to ghosts and aliens is best for us. From there, I defer! I am not the one who got this far, I only hope to go forward with |
Addressing apache#356 with a comment, since this is a type issue
Added a comment since it seems appropriate in this case: abstractive@1537ad8 |
My point is that if we go with your PR as is (where priority is given to the
Basically we |
Moving forward on apache#358 with a bit more aggressive change per discussion
I agree! But... some forest: The entire section is kinda moot and has code-smell, because it rests on As a bit more of an aggressive/refactory PR then, I optimized the piece going to run either way ( const responseHeaders = {
uri: scrubURL(req.url),
statusCode,
...(response.headers ?? {})
};
if (!response.status) {
log({ err: 'socket', body, headers: responseHeaders })
if (reject) {
// since #relax might have sent Error rather than Response:
const statusText = response.cause?.toString() ?? response.message
reject(new Error(`error happened in your connection. Reason: ${statusText}`))
}
return
} What do you think? Beyond a happy-medium and get some refactoring started? |
This is better. There's a bunch of stuff in the code that has festered from the request --> axios --> fetch generations, so there's definitely a nicer-looking solution out there (in the future). I'm more worried about not giving node users a worse error message and your latest code snippet fixes that. |
I feel the tension! I like to start to turn the overall insurmountable-feeling table while dealing with the immediate. I hope to help, piece by piece, if I can. I admire the care for how the various engines will behave. Hopefully this PR works out. That snippet is the new state of the branch; let me know if there are any other concerns that come to mind @glynnbird. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tidy up while still giving the Node user the "cause" and the Bun user the "message" 👍
One approach to #356; refactor likely needed ( along with #355 ) to wring out design errors.
Overview
Intended to resolve #356
That was originally seen as fixing a syntax error, but the syntax error existed because of a theory error.
By that theory error, when an
Error
was thrown on a request, the message is being lost.Reasoning
This has already met
!response.status
which means it is more than likelyerror
and notresponse
being calledresponse
due to the theory error, since the design does not have a separateresponseHandler
for errors.Because of that, I check
response.message
first, thenresponse.cause?.toString()
( includes fix requested by #356 )Testing recommendations
response.cause
doesn't exist #356 (comment) case )Since this is a small change of one line ... but might trigger a refactor since there is a theory error still: