undici icon indicating copy to clipboard operation
undici copied to clipboard

Extend ResponseError interceptor body parsing capabilities

Open marcoreni opened this issue 2 months ago • 1 comments

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

marcoreni avatar Nov 12 '25 10:11 marcoreni

Extending the option to extend MIMEtypes support should be enough

metcoder95 avatar Nov 13 '25 07:11 metcoder95