nodejs / nodejs/undici

Extend ResponseError interceptor body parsing capabilities

Open
#4,667 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement interceptors
Dominant language
JavaScript
Stars
7.7k
Forks
879
Avg merge
2d 16h
Merged PRs (30d)
68

Description

This would solve...

ResponseError interceptor adds the body to the error only if the content type is application/json or text/plain. However, some APIs may have more uncommon content types (for example, they may return text/xml. There are also some more exotic ones: meta sends text/javascript whenever the accept header is missing in the request, and Contentful CMS Management APIs use application/vnd.contentful.management.v1+json, even if there's JSON in the responses).

In these scenarios, ResponseError does not include the body and returns an empty string.

The implementation should look like...

ResponseError may expose a parseBody hook so that, without adding complexitiy to Undici itself, users may add custom extraction/parsing whenever needed.

I have also considered...

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ResponseError interceptor implementation and its current body parsing logic. Define how a parseBody hook should handle uncommon content types without changing existing JSON or text behavior, then add coverage for custom parsing and verify the response body is included in the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.