Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

requestFragment type definition does not match implementation #327

@atkinchris

Description

@atkinchris

The type definition for requestFragment does not match the implementation.

It is a single function that takes 5 arguments and returns a promise.

, requestFragment?: (filterHeaders: (attributes: Attributes, req: IncomingMessage) => object, url: Url, attributes: Attributes, req: IncomingMessage, span?: Span) => Promise<ServerResponse>

However, the implementation is a function that takes a single argument, and returns a function that takes 4 arguments and returns a promise.

module.exports = filterHeaders => (
fragmentUrl,
fragmentAttributes,
request,
span = null
) =>
new Promise((resolve, reject) => {

The response type is ServerResponse, but in on('response', response => ...) is an IncomingMessage

fragmentRequest.on('response', response => {
if (response.statusCode >= 500) {
reject(new Error('Internal Server Error'));
} else {
resolve(response);
}
});

Argument url is an attribute from the tag, and therefore a string, not an instantiated URL object.
https://github.com/atkinchris/tailor/blob/3123dc4d182aef299e7ec1385005cbcf1368134b/lib/fragment.js#L116-L118

I think the correct type definition should be:

(filterHeaders: (attributes: Attributes, req: IncomingMessage) => object) => (url: string, attributes: Attributes, req: IncomingMessage, span?: Span) => Promise<IncomingMessage> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions