-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
fetch.ts
34 lines (29 loc) · 1.12 KB
/
fetch.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createTransport } from '@sentry/core';
import { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
import { FetchImpl, getNativeFetchImplementation } from './utils';
export interface FetchTransportOptions extends BaseTransportOptions {
requestOptions?: RequestInit;
}
/**
* Creates a Transport that uses the Fetch API to send events to Sentry.
*/
export function makeFetchTransport(
options: FetchTransportOptions,
nativeFetch: FetchImpl = getNativeFetchImplementation(),
): Transport {
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
const requestOptions: RequestInit = {
body: request.body,
method: 'POST',
referrerPolicy: 'origin',
...options.requestOptions,
};
return nativeFetch(options.url, requestOptions).then(response => ({
headers: {
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
'retry-after': response.headers.get('Retry-After'),
},
}));
}
return createTransport({ bufferSize: options.bufferSize }, makeRequest);
}