Skip to content

Commit

Permalink
Building up lighter SendOptions where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealAgentK committed Oct 22, 2024
1 parent a74d799 commit 7f2b1b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/raygun.transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ export function send(
const data = Buffer.from(options.message);

const httpOptions = {
host: options.http.host || API_HOST,
port: options.http.port || 443,
host: options.http?.host || API_HOST,
port: options.http?.port || 443,
path: path,
method: "POST",
headers: {
Host: API_HOST,
"Content-Type": "application/json",
"Content-Length": data.length,
"X-ApiKey": options.http.apiKey,
"X-ApiKey": options.http?.apiKey,
},
};

// Wrap HTTP request in Promise
return new Promise((resolve, reject) => {
const httpLib = options.http.useSSL ? https : http;
const httpLib = options.http?.useSSL ? https : http;
const request = httpLib.request(
httpOptions,
(response: IncomingMessage) => {
Expand All @@ -67,7 +67,7 @@ export function send(
},
);

if (options.http.timeout) {
if (options.http?.timeout) {
debug(`[raygun.transport.ts] Timeout set: ${options.http.timeout}ms`);
request.setTimeout(options.http.timeout, () => {
console.error(
Expand Down
14 changes: 10 additions & 4 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,18 @@ class Raygun {
transport
.send({
message,
http: httpOptions,
...(transport instanceof RaygunBatchTransport
? {}
: {
http: httpOptions
}),
})
.then((response) => {
debug(
`[raygun.ts] Sent message from offline transport: ${response}`,
);
if (!(transport instanceof RaygunBatchTransport)) {
debug(

Check failure on line 612 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 16 spaces but found 18

Check failure on line 612 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 16 spaces but found 18

Check failure on line 612 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Expected indentation of 16 spaces but found 18
`[raygun.ts] Sent message from offline transport: ${response?.statusCode} ${response?.statusMessage}`,

Check failure on line 613 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 14 spaces but found 16

Check failure on line 613 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 14 spaces but found 16

Check failure on line 613 in lib/raygun.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Expected indentation of 14 spaces but found 16
);
}
})
.catch((error) => {
console.error(
Expand Down

0 comments on commit 7f2b1b5

Please sign in to comment.