forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeFetchSubmissionClient.ts
More file actions
36 lines (32 loc) · 1.18 KB
/
NodeFetchSubmissionClient.ts
File metadata and controls
36 lines (32 loc) · 1.18 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
31
32
33
34
35
36
import {
default as fetch,
RequestInit
} from "node-fetch";
import {
Configuration,
FetchOptions,
Response,
SubmissionClientBase
} from "@exceptionless/core";
export class NodeFetchSubmissionClient extends SubmissionClientBase {
protected async fetch<T>(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())
}
}