forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserFetchSubmissionClient.ts
More file actions
30 lines (27 loc) · 1.1 KB
/
BrowserFetchSubmissionClient.ts
File metadata and controls
30 lines (27 loc) · 1.1 KB
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
import {
FetchOptions,
Response,
SubmissionClientBase
} from "@exceptionless/core";
export class BrowserFetchSubmissionClient extends SubmissionClientBase {
protected async fetch(url: string, options: FetchOptions): Promise<Response> {
// TODO: Figure out how to set a 10000 timeout.
const requestOptions: RequestInit = {
method: options.method,
headers: {
"Accept": "application/json",
"Authorization": `Bearer ${this.config.apiKey}`,
"User-Agent": this.config.userAgent
},
body: options.body
};
// TODO: Can we properly calculate content size?
if (options.method === "POST") {
requestOptions.headers["Content-Type"] = "application/json";
}
const response = await fetch(url, requestOptions);
const rateLimitRemaining: number = parseInt(response.headers.get(this.RateLimitRemainingHeader), 10);
const settingsVersion: number = parseInt(response.headers.get(this.ConfigurationVersionHeader), 10);
return new Response(response.status, response.statusText, rateLimitRemaining, settingsVersion, await response.text())
}
}