Skip to content

Commit

Permalink
fix(otlp-exporter-base): improve fetch error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
sugi committed Jan 28, 2023
1 parent a0aa0c9 commit 7a36740
Showing 1 changed file with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,32 @@ export function sendWithFetch(
signal: controller.signal,
body,
})
.then(response => {
if (response.ok) {
response.text().then(
t => diag.debug('Request Success', t),
() => {}
);
onSuccess();
} else {
onError(
new OTLPExporterError(
`Failed to export with fetch: (${response.status} ${response.statusText})`,
response.status
)
);
}
})
.catch((e: Error) => {
if (e.name === 'AbortError') {
onError(new OTLPExporterError('Request Timeout'));
} else {
onError(new OTLPExporterError(`Request Fail: ${e.name} ${e.message}`));
.then(
response => {
if (response.ok) {
response.text().then(
t => diag.debug('Request Success', t),
() => {}
);
onSuccess();
} else {
onError(
new OTLPExporterError(
`Failed to export with fetch: (${response.status} ${response.statusText})`,
response.status
)
);
}
},
(e: Error) => {
if (e.name === 'AbortError') {
onError(new OTLPExporterError('Request Timeout'));
} else {
onError(
new OTLPExporterError(`Request Fail: ${e.name} ${e.message}`)
);
}
}
})
)
.finally(() => clearTimeout(timerId));
}

0 comments on commit 7a36740

Please sign in to comment.