Skip to content

Commit

Permalink
fix(ipv6): fetch tries both addresses sometimes and returns Aggregate…
Browse files Browse the repository at this point in the history
…Error
  • Loading branch information
djMax committed Nov 9, 2023
1 parent cf8ab36 commit b18c2f6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 84 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ tsconfig.build.json
.prettierrc.js
.eslintrc.js
.commitlintrc.json
vitest.config.ts
14 changes: 0 additions & 14 deletions .prettierrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ test('Basic function', async () => {
server.listen(12345, accept);
});

await fetch('http://localhost:12345');
await fetch('http://localhost:12345', { keepalive: false });
expect(config.onRequest).toHaveBeenCalledTimes(1);
await fetch('http://localhost:12345', { headers: { 'x-error': '1' } });
await fetch('http://localhost:12345', { headers: { 'x-error': '1' }, keepalive: false });
expect(config.onRequest).toHaveBeenCalledTimes(2);

await new Promise<void>((accept, reject) => {
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
}) => void;
}

function getMessage(error: Error) {
if (error instanceof AggregateError) {
return error.errors.map((e) => e.message).join(', ');
}
return error.message;
}

// Get the content-length from undici response headers.
// `headers` is an Array of buffers: [k, v, k, v, ...].
// If the header is not present, or has an invalid value, this returns null.
Expand Down Expand Up @@ -215,7 +222,7 @@ export class FetchInstrumentation implements Instrumentation {
span.recordException(error);
span.setStatus({
code: SpanStatusCode.ERROR,
message: error.message,
message: getMessage(error),
});
span.end();
}
Expand Down
11 changes: 0 additions & 11 deletions tsconfig.build.json

This file was deleted.

42 changes: 0 additions & 42 deletions tsconfig.json

This file was deleted.

0 comments on commit b18c2f6

Please sign in to comment.