Does undici take care of consuming the response body if throwOnError: true? #3440
-
Hi everyone, I have a question regarding error handling and garbage collection in Undici. Here’s a example of a request I’m making: try {
const response = await request("http://example.com", {
method: "POST",
body: JSON.stringify({ /* some body */ }),
throwOnError: true,
});
} catch (error) {
// Handle error
} If the request fails with a 4xx or 5xx status code, the function throws a Is this correct? Can I assume that, in this scenario, Undici will handle garbage collection correctly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
👋 Yes, if the request fails with a range grater or equal than It is worth mentioning that this will change in the future major. If you want to preserve this behaviour, you'll need to use an interceptor instead. |
Beta Was this translation helpful? Give feedback.
👋
Yes, if the request fails with a range grater or equal than
400
, Undici will read the body and attach it to the Error's properties.It is worth mentioning that this will change in the future major. If you want to preserve this behaviour, you'll need to use an interceptor instead.