Capture error message, otherwise capture cause of HTTP failure#358
Capture error message, otherwise capture cause of HTTP failure#358glynnbird merged 3 commits intoapache:mainfrom
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.messageinstead? 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. |
glynnbird
left a comment
There was a problem hiding this comment.
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
Errorwas thrown on a request, the message is being lost.Reasoning
This has already met
!response.statuswhich means it is more than likelyerrorand notresponsebeing calledresponsedue to the theory error, since the design does not have a separateresponseHandlerfor errors.Because of that, I check
response.messagefirst, thenresponse.cause?.toString()( includes fix requested by #356 )Testing recommendations
response.causedoesn'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: