Skip to content

Extend ResponseError interceptor body parsing capabilities #4667

@marcoreni

Description

@marcoreni

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions